簡體   English   中英

重新縮放 y 軸 ggplot (geom_bar)

[英]Rescale y axis ggplot (geom_bar)

這應該是一個非常簡單的問題! 我想用錯誤欄制作一個條形圖,我正在使用以下代碼:

ggplot(data = bars, aes(x=c("1","2","3"), y=V2, fill = names)) + 
  geom_bar(position=position_dodge(), stat="identity", alpha = 0.7) +
  geom_errorbar(aes(ymin=V1, ymax=V3))+
  theme(legend.position='none')+
  coord_cartesian(ylim=c(0,10))

但是,我有兩個問題: 1. 我希望條形從 y = 0 開始 2. 我不喜歡 y 軸上的刻度。 我想要只有一位小數和更少刻度的數字。

這是我的實際情節:帶有誤差條的條形圖

對於第一個問題(如果我理解正確的話)你可以使用ylim

... + ylim(0.2, NA)

NA使上限自由。

第二,我建議使用pretty_breaks from scale

library(scales)
... + scale_y_continuous(breaks=pretty_breaks(n=5))

暫無
暫無

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

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