简体   繁体   中英

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. Obviously compounds have different scales and Y axis are not aligned. I wish align them by zero on Y axis.

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.

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))

Here an example of how appear my final plot with Y axis out of phase.

If I understand it correctly, you want the line at y=0 to appear at the same height in all plots. 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:

+ 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.

https://ggplot2.tidyverse.org/reference/lims.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM