首页 > 解决方案 > 使用 24 小时制数据创建圆形图的方法是什么?

问题描述

我正在尝试使用围绕中心点绘制的一组数据来创建一个圆形图。我在网上找到的代码可以做到,但是 Y 轴太大以至于图形没有用。我想将 Y 轴限制为 95-120,但是当我使用Y_scale_continuous(limit=c(95,120))它时,它会掉线。

数据:

"","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

代码:

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))

标签: rggplot2

解决方案


也许这里的解决方案只是更改您的数据?从数学上讲,这与将轴从零移开一样。

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))

在此处输入图像描述

这可能会使图表更难解释,因此您需要解释任何这样的操作。如果相对值显着,这可以帮助解释,如果绝对值显着,这种调整的范围从令人困惑到相当误导。


推荐阅读