Skip to content

Instantly share code, notes, and snippets.

@bestdan
Created May 21, 2020 11:54
Show Gist options
  • Save bestdan/0b4ade4e19f49dfbb60d281b85bb61a3 to your computer and use it in GitHub Desktop.
Save bestdan/0b4ade4e19f49dfbb60d281b85bb61a3 to your computer and use it in GitHub Desktop.
Plotting a polar radar chart in R
library(ggplot2)
library(tidyr)
library(dplyr)
# Normalize
data(mtcars)
mtcars_norm <- as.data.frame(apply(mtcars, 2, scale))
# Make long
mtcars_long <- pivot_longer(mtcars_norm, cols = colnames(mtcars), values_to = "value")
plotPolar <- function(rdata){
ggplot(rdata,
aes(x = name,
y = value)) +
geom_point(aes(col = as.factor(name)),
alpha = 0.3,
position = position_jitter(0.2)) +
geom_hline(yintercept = 0) +
theme(axis.title.y = element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x = element_text(size = 10),
legend.position = 'none') +
coord_polar()
}
print(plotPolar(mtcars_long))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment