如何动态调整y轴范围是ggplot2?

jra*_*ara 3 r ggplot2

如何调整y轴以便在这种情节中正确显示注释?

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在例如在facet G中,'Ideal'的注释没有正确显示.应该动态计算Y轴范围,以便在条形上方始终存在一些注释空间.所以我不能使用固定的y轴范围.

Tro*_*roy 6

如何+ scale_y_continuous(expand=c(0.15,0))在现有代码之后使用:

expand= 期望乘数和加法比例因子的2数向量

在此输入图像描述