Home > Software engineering >  Add guide lines for y-axis when using coord_polar() for polar histogram
Add guide lines for y-axis when using coord_polar() for polar histogram

Time:03-15

I want to create a polar histogram like this

enter image description here

with dashed lines going from the y-axis ticks to the 0/360 line to help the reader to map the count to the histogram's bar length. I have added the dashed lines with power point but I am wondering whether it is possible to add this with ggplot.

I used this code

library(ggplot2)
# Seed
set.seed(20220315)

# Create random data from 0 to 360
example_dat <- data.frame(rot_y = runif(1000, min = 0, max = 360))


# Create polar plot
ggplot(example_dat, aes(x = rot_y ))  
  geom_histogram(binwidth = 15, boundary = -7.5, colour = "black", size = .25)  
  scale_x_continuous(limits = c(0,360),
                     breaks = seq(0, 360, by = 60),
                     minor_breaks = seq(0, 360, by = 15))   
  coord_polar()  
  labs(title = 'Polar histogram of y rotation',
       y = 'Count',
       x = '')

to generate this plot

enter image description here

I am aware of the work around for drawing a line segment like in this solution: enter image description here

  • Related