【问题标题】:Align bars and ticks with geom_bar使用 geom_bar 对齐条形图和刻度线
【发布时间】:2018-02-25 20:11:00
【问题描述】:

我的问题与 stibu 的 answer 有关。我正在使用geom_bar,并且我试图将条形置于 x 轴刻度之间的中心(参见答案的第二张图)。

这是一个例子:

grp<-letters[1:13]
count<-c(38,591,549,487,419,363,276,276,164,68,31,10,5)
data<-data.frame(grp,count)
ggplot(data,aes(x=grp,y=count))+geom_bar(stat="identity")

这给出了以下内容:

  • 我的 x 轴由字符变量组成,所以我不能使用“+0,5”技巧。
  • 没有boundarycenter 建议的geom_bar 选项here

那么如何对齐条形,使其左边框与刻度线对齐?

我使用的是 R 版本 3.4.0 和 RStudio 1.0.143。

【问题讨论】:

    标签: r ggplot2 geom-bar


    【解决方案1】:

    这是你想要的吗?

    require(ggplot2)
    
    grp<-letters[1:13]
    count<-c(38,591,549,487,419,363,276,276,164,68,31,10,5)
    data<-data.frame(grp,count)
    ggplot(data,aes(x=grp,y=count))+
      geom_bar(stat="identity",  
               width = 0.9, 
               position = position_nudge(x = 0.5)) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多