TCS
TCS

Reputation: 471

Plot circular histogram with offset in ggplot2

I have time-of-day data that I think will plot best as a polar histogram (rose plot). I would like to end up with something like this:

enter image description here

instead of what I get:

enter image description here

In particular I want to spread out the small values to make them easier to see, but on the polar coordinate system the width goes to zero, making it hard to read. Is there a way to do this using ggplot?

Here are the data:

   Arrival_h<-c(3,3,4,5,5,6,6,7,7,7,7,8,9,9,9,9,9,9,9,9,10,10,10,10,11,11,11,11,11,12,12,12,12,12,13,13,13,13,14,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,19,19)
  HKArr<-data.frame(Arrival_h)

Upvotes: 1

Views: 2816

Answers (1)

TCS
TCS

Reputation: 471

On a whim I decided to try modifying the y axis and it solves the problem:

This is a better layout than I gave before without the offset

p<-ggplot(data=HKArr,aes(x=Arrival_h))+
  geom_histogram(fill='blue',color='black',breaks=c(1:24))+coord_polar()+
  scale_x_continuous("", limits = c(0, 24), 
                     breaks = seq(0, 24), labels = seq(0,24))
p

which produces this: no y offset

...adding the y offset:

p<-ggplot(data=HKArr,aes(x=Arrival_h))+
  geom_histogram(fill='blue',color='black',breaks=c(1:24))+coord_polar()+
  scale_x_continuous("", limits = c(0, 24), 
                     breaks = seq(0, 24), labels = seq(0,24))+
  scale_y_continuous("",limits=c(-2,10))
p

Gives this, which I think is easier to read:

Arrival time--with offset zeros

Upvotes: 4

Related Questions