2013-11-27 58 views
3

如何調整y軸,使註釋在這種情節中也能正確顯示?如何動態調整y軸範圍是ggplot2?

library(ggplot2) 

ggplot(diamonds, aes(x = cut, y = depth)) + 
    facet_wrap(~ color) + 
    stat_summary(fun.y = sum, geom="bar", fill = "yellow", aes(label=cut, vjust = 0)) + 
    stat_summary(fun.y = sum, geom="text", aes(label=cut), vjust = 0) 

enter image description here

現在例如在小面ģ註釋爲「理想」未正確顯示。 Y軸範圍應該動態計算,這樣在條上方總會有一些註釋空間。所以我不能使用固定的Y軸範圍。

回答

6

談談你現有的代碼之後使用+ scale_y_continuous(expand=c(0.15,0))

expand=預計,乘2號向量和添加劑的比例因子

enter image description here