简体   繁体   English

如何使用 R 中的 plot_grid 函数在图之间将 y 轴对齐 0?

[英]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.

相关问题 如何在 R 中使用 `ggdraw` 和 `plot_grid()` 在 X 和 Y 轴上创建一个公共标题? - How to create a common title in X and Y axis in an arrange of plots using `ggdraw` and `plot_grid()` in R? 如何将 Y 轴上的 0 与 plot 网格对齐? - How align plots by 0 on Y axis with plot grid? 在 r 中,如何控制组合图 (plot_grid) 中图与 x 轴的比例? - In r, how to control proportion of plots versus x-axis in a combined plot (plot_grid)? Cowplot程序包:在R中使用plot_grid()将许多图安排成一个图后,如何垂直向下调整图例 - Cowplot Package: How to align legends vertically downwards after arranging many plots into one plot using plot_grid() in R 如何使用`cowplot` package中的`plot_grid`对齐包含在最后一列图中的图例? - How to align legends included in the plots of the last column of an arrange of plots using `plot_grid` from `cowplot` package? 如何使用 R 中的“plot_grid”减少一列图的 plot 边距? - How to reduce plot margins of one column of plots of an arrange of plots using `plot_grid` in R? 如何使用plot_grid放置没有任何空间的绘图? - How to put plots without any space using plot_grid? 在辅助 y 轴上对齐网格 - 基础 plot R - Align grid in secundary y axis - base plot R 如何使用R中的plot_grid()函数绘制几个seqplots(TraMineR包)? - How to plot several seqplots (TraMineR package) using plot_grid() function in R? 使用 coord_equal() 时使用 cowplot::plot_grid() 垂直对齐不同高度的图 - Vertically align of plots of different heights using cowplot::plot_grid() when using coord_equal()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM