0

I have a set of angles that I want to plot, compare and visualise in a circular scale and then patch them into a comparative figure panel. I understand the plot function does what I want for an individual dataset. However, I have multiple of them and want to compare and visualise them with better aesthetics (like in ggplots). Primarily I want to overlay 2 circles on each other and compare them. Here is a sample of my data

a<-c(289.25, 279.61, 288.09, 208.22, 295.74, 214.48, 192.51, 269.93, 225.89, 215.65)
a
ap<-circular(a, template = "geographics", modulo = "2pi")
plot(ap)
arrows.circular(ap, col = "blue", length = 0.25, angle = 30)

enter image description here

I tried the as.ggplot function from the ggplotify package as suggested here. However, I cannot add arrows or layers to my base plot by using as.ggplot (i.e) It converts the plot(ap)part in my example into a ggplot object but the next part (arrows.circular(ap, col = "blue", length = 0.25, angle = 30) is not working.

Is there a way I can draw these plots in ggplot or is there a way to convert the layers of base plots into ggplots using as.ggplot??

Any suggestions would be helpful. Thanks in advance!

1 Answers1

0

You can recreate the plot using ggplot like this:

library(ggplot2)

ggplot(data.frame(a = a %% (2 * pi))) +
  geom_segment(aes(x = a, xend = a, y = 0, yend = 1), color = 'blue',
               arrow = arrow()) +
  geom_hline(yintercept = 1) +
  annotate('text', x = 0:3 * pi/2, y = 0.9, label = c('N', 'E', 'S', 'W'),
           size = 5) +
  geom_point(aes(x = a, y = 1)) +
  scale_x_continuous(limits = c(0, 2 * pi)) +
  coord_polar() +
  theme_void()

enter image description here

And it's certainly possible to alter its appearance to make it look a bit 'softer' and more professional, though this is of course a matter of taste:

library(ggplot2)

ggplot(data.frame(a = a %% (2 * pi))) +
  annotate('rect', xmin = -Inf, xmax = Inf, ymin = 0, ymax = 1,
           fill = 'gray97') +
  geom_hline(yintercept = 1, color = 'gray60') +
  geom_segment(aes(x = a, xend = a, y = 0, yend = 1), 
               color = 'deepskyblue4', size = 1, alpha = 0.5,
               arrow = arrow(angle = 25, length = unit(4, 'mm'))) +
  annotate('text', x = 0:3 * pi/2, y = 0.9, label = c('N', 'E', 'S', 'W'),
           size = 7, fontface = 2, color = 'gray30') +
  geom_point(aes(x = a, y = 1)) +
  scale_x_continuous(limits = c(0, 2 * pi)) +
  coord_polar() +
  theme_void() +
  theme(plot.background = element_rect(color = NA, fill = '#ecf1f4'))

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87