【问题标题】:Changing the Y-scale using coord_polar使用 coord_polar 更改 Y 比例
【发布时间】:2021-03-30 10:00:57
【问题描述】:

嗨,我是编码新手,我一直在关注如何在 RStudio 中制作圆形条形图的 youtube 教程。问题是我使用的数据高达数千万,并且希望放大 y 尺度以更详细地查看数据。我尝试使用coord_cartesian 并设置ylim,但没有任何变化并得到消息“坐标系已经存在”

如何将 y 比例更改为 40,000,000 到 70,000,000 之间?

这就是我所拥有的


#create data
month <- c('Mar 19', 'Apr 19', 'May 19', 'June 19', 'Jul 19', 'Aug 19', 'Sept 19','Oct 19', 'Nov 19', 'Dec 19', 'Jan 20', 'Feb 20')
rides <- c(67583312, 59590909,  68449486,   60163410,   63675286,   66059525,   63148128,   66208467,   65481522,   58539077,   57098170,   60289465)


df=data.frame(month,rides)
df



ggplot(df,aes(x=month,y=rides, fill=month))+
    geom_bar(stat='identity')+
    theme(legend.position = "none")+
    coord_cartesian(ylim(40000000, 70000000), clip = "on")+
    coord_polar(start=0)
 
 

【问题讨论】:

    标签: r ggplot2 graph scale


    【解决方案1】:

    一种解决方法是更改​​ y 变量的值以用于绘图,然后手动调整 y 轴的标签。

    ggplot(df,aes(x=month, y=rides -40000000, fill=month))+
      geom_bar(stat='identity')+
      theme(legend.position = "none")+
      coord_polar(start = 0) +
      scale_y_continuous(labels = c(40000000, 50000000, 60000000, 70000000))
    

    输出:

    不过,我不确定这是否是一个好方法。直觉上,人们可能会期望中心为 0,而不是 40,000,000。但希望其他人可以发布一个干净的解决方案。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2019-05-09
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多