[英]Is there an R function to get the max y-axis when doing ggplot facet?
I have a facet graph where it's free = scales
, so each plot has a different y-axis.我有一个
free = scales
的构面图,因此每个 plot 都有不同的 y 轴。 I want to know if there is a function that can return the max y-axis so that the text always appears on the top of each plot, like this:我想知道是否有一个 function 可以返回最大 y 轴,以便文本始终出现在每个 plot 的顶部,如下所示:
geom_text(data,aes(x=25,y=max_y,label="test text"))
I haven't been able to find any resources similar to this issue and was struggling to see if I could extract the layout information with ggplot_build or g_table.我无法找到与此问题类似的任何资源,并且正在努力查看是否可以使用 ggplot_build 或 g_table 提取布局信息。 If I missed a resource, please let me know.
如果我错过了资源,请告诉我。 Thank you in advance.
先感谢您。
ggplot(mtcars, aes(wt,mpg)) +
geom_point() +
annotate("text", x = -Inf, y = Inf, label= "Test",
hjust = -0.2, vjust = 1.2) +
facet_wrap(~gear, scales = "free")
Or with facet-varying data:或者使用 facet-varying 数据:
ggplot(mtcars, aes(wt,mpg)) +
geom_point() +
geom_text(data = data.frame(wt = -Inf, mpg = Inf, gear = 3:5,
label = c("Test", "More", "And more")),
aes(label = label),
hjust = -0.2, vjust = 1.2) +
facet_wrap(~gear, scales = "free")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.