brc
brc

Reputation: 99

What is a method for creating a circle plot using data on 24-hour clock?

I am trying to create a circle plot with the means of a set of data plotted around a center point. The code I have found online does it but the Y axis so big that the graphic isn't useful. I want to limit the Y-axis to 95-120 but when I use Y_scale_continuous(limit=c(95,120)) it drops the bars.

Data:

"","Hour","me"
"1",0,98.9192
"2",1,100.756333333333
"3",2,101.6815
"4",3,98.6551666666667
"5",4,102.668666666667
"6",5,104.024571428571
"7",6,106.137
"8",7,103.6535
"9",8,107.868333333333
"10",9,112.261428571429
"11",10,114.99
"12",11,113.452714285714
"13",12,110.534285714286
"14",13,112.974285714286
"15",14,112.731428571429
"16",15,104.658571428571
"17",16,112.271
"18",17,108.386666666667
"19",18,113.968857142857
"20",19,107.287142857143
"21",20,110.583
"22",21,102.811714285714
"23",22,105.983571428571
"24",23,100.98625

Code:

p<-ggplot(c, aes(x = Hour, y=me)) + 
         geom_bar(breaks = seq(0,24), width = 2, colour="grey",stat = "identity") +
         theme_minimal() + 
         scale_fill_brewer()+coord_polar(start=0)+
         scale_x_continuous("", limits = c(0, 24), breaks = seq(0, 24), labels = seq(0,24))

Upvotes: 2

Views: 1720

Answers (2)

Axeman
Axeman

Reputation: 35397

Bars are good at showing proportional changes between values. If you let go of the 0 baseline, they do no longer have that property and this will mislead many people. If a bar is twice is tall, it should encode a value twice as large. ggplot2 closely follows that philosophy. Consider an alternative visualization. Perhaps a simple line graph:

ggplot(d, aes(x = Hour, y=me)) + 
  geom_polygon(fill = NA, col = 1) +
  geom_point(size = 5) +
  theme_minimal() + 
  coord_polar() +
  scale_x_continuous("", breaks = 0:24, limits = c(0, 24)) +
  ylim(90, 115) # adjust as you like

enter image description here

Upvotes: 3

Ryan
Ryan

Reputation: 1072

Perhaps the solution here is just to change your data? Mathematically speaking, this accomplishes the same thing as shifting the axis away from zero.

ggplot(df, aes(x = Hour, y=me - 95)) +
  geom_bar(width = 2, colour="grey",stat = "identity") +
  theme_minimal() +
  scale_fill_brewer() +
  coord_polar(start=0) +
  scale_x_continuous("", limits = c(0, 24), breaks = seq(0, 24), labels = seq(0,24))

enter image description here

This likely makes the chart harder to interpret and therefore you would need to explain any manipulation like this. If the relative values are significant, this can help interpretation, If the absolute values are significant, this kind of adjustment can range from confusing to quite misleading.

Upvotes: 2

Related Questions