2013-11-27 57 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