簡體   English   中英

將條和刻度與geom_bar對齊

[英]Align bars and ticks with geom_bar

我的問題與stibu的答案有關。 我正在使用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選項,建議在這里

那么,如何對齊條以使其左邊框與刻度線對齊?

我正在使用R版本3.4.0和RStudio 1.0.143。

那是你要的嗎 ?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM