[英]How to align y axis by 0 between plots with plot_grid function in R?
I made several weekley plots of different gaseous compounds (BVOCs) with ggplot and I put them together with plot_grid
function.我用 ggplot 制作了几个不同气体化合物 (BVOC) 的周线图,并用
plot_grid
函数将它们放在一起。 Obviously compounds have different scales and Y axis are not aligned.显然,化合物具有不同的比例并且 Y 轴未对齐。 I wish align them by zero on Y axis.
我希望在 Y 轴上将它们对齐为零。
I think that I can avoid to share the dataset and the single plots code, because the point is on plot_grid
function that put them together.我认为我可以避免共享数据集和单个绘图代码,因为重点在于将它们放在一起的
plot_grid
函数。
Here the plot_grid
function that I used: plot_grid(metmax,acetalmax,formicmax,acetmax,nrow = 4,align = "hv",rel_widths= c(1,1,1,1),rel_heights = c(1.2,1.2,1.2,1.2))
这里我使用的
plot_grid
函数: plot_grid(metmax,acetalmax,formicmax,acetmax,nrow = 4,align = "hv",rel_widths= c(1,1,1,1),rel_heights = c(1.2,1.2,1.2,1.2))
Here an example of how appear my final plot with Y axis out of phase.这是一个示例,说明 Y 轴异相时我的最终图如何出现。
If I understand it correctly, you want the line at y=0 to appear at the same height in all plots.如果我理解正确,您希望 y=0 处的线在所有图中出现在相同的高度。 That would require them all to have the same range and, by consequence, the same scale.
这将要求它们都具有相同的范围,因此具有相同的比例。
You can add to your ggplot() call the following:您可以将以下内容添加到 ggplot() 调用中:
+ ylim(min_value, max_value)
min_value and max_value can be calculated by the script by looking at the range of values occurring in your plot data.脚本可以通过查看绘图数据中出现的值范围来计算 min_value 和 max_value。
https://ggplot2.tidyverse.org/reference/lims.html https://ggplot2.tidyverse.org/reference/lims.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.