5

I'm looking to make a radar plot for multivariate data, a task simple enough for excel.

The problem comes when I would like to also plot some error bars on this. From what I understand, I cannot do this in excel. Is this possible on R?

Or can someone suggest an alternative? I have 32 single value dimensions.

Thanks!

A. Vihani
  • 81
  • 2
  • 8

1 Answers1

15

I don't much like radar charts but here are some ideas to get you going, drawing on this approach. I like the look of my option 1 best, but I'm not sure how to solve the gap between var32 and var1 (I have some ideas, but a bit awkward).

library(tidyverse)
library(ggplot2)
library(scales)

# make some mock data
mydata <- data.frame(variable = paste0("Var", 1:32),
                     midpoint = rnorm(32),
                     stderr = rnorm(32, 1, 0.1),
                     stringsAsFactors = FALSE) %>%
  mutate(upper = midpoint + 1.96 * stderr,
         lower = midpoint - 1.96 * stderr) %>%
  mutate(variable = factor(variable, levels = variable)) 

# Option 1:
mydata %>%
  ggplot(aes(x = variable, y = midpoint, group = 1)) +
  geom_ribbon(aes(ymin = lower, ymax = upper), fill = "grey50", alpha = 0.5) +
  geom_line(colour = "purple") +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  coord_polar() +
  labs(x = "", y = "")

enter image description here

# Option 2:
mydata %>%
  gather(measure, value, -variable, -stderr) %>%
  ggplot(aes(x = variable, y = value, colour = measure, group = measure, linetype = measure)) +
  geom_polygon(fill = NA) +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  coord_polar() +
  scale_colour_manual(values = c("steelblue", "black", "steelblue")) +
  scale_linetype_manual(values = c(2,1,2)) +
  labs(x = "", y = "")

enter image description here

# Option 3:
mydata %>%
  ggplot(aes(x = variable, y = midpoint, group = 1)) +
  geom_polygon(fill = NA, colour = "purple") +
  geom_segment(aes(xend = variable, y = lower, yend = upper), colour = "grey50") +
  geom_point(colour = "purple") +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  theme(panel.grid.major.x = element_blank()) +
  coord_polar() +
  labs(x = "", y = "")

enter image description here

Edit / addition

I think I prefer this one:

# Option 4:
mydata %>%
  ggplot(aes(x = variable, y = midpoint, group = 1)) +
  geom_polygon(aes(y = upper), fill = "grey50", alpha = 0.5) +
  geom_polygon(aes(y = lower), fill = "grey99", alpha = 0.7) +
  geom_polygon(fill = NA, colour = "purple") +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  coord_polar() +
  labs(x = "", y = "")

enter image description here

Peter Ellis
  • 5,694
  • 30
  • 46
  • This is great! Exactly what I am trying to depict. Thanks! – A. Vihani Jan 06 '17 at 03:05
  • Any idea on how to plot combine all three of these into one? I'm actually looking to plot multiple radars on a single graph. – A. Vihani Jan 08 '17 at 21:35
  • Sounds messy. I would use the final option from above, and have different colored fill for each radar. Unlikely to be readable with more than two. – Peter Ellis Jan 14 '17 at 18:59
  • I used option 4 above to make a multi-layered radar chart where I alternate between a shade and white, like this: `geom_polygon(aes(y = One_upper), fill = "#ac07e3", alpha = 0.5) +` `geom_polygon(aes(y = One_lower), fill = "white", alpha=1)`, but the problem is, since I have to use "white" to achieve a shaded confidence interval, and I have multiple such layers, some of those colored areas are obscured by white. This is what I get: https://imgur.com/tLp4KCh But the red area should actually look like this: https://imgur.com/B5U5kLo Any tips on how to make all colors visible? Thank you! – user3116101 Jul 26 '21 at 19:26