y axis in facet_wrap

Dear R users,

I have created one monthly plot with facet_wrap. So in the plot I have 3 rows and 4 columns. Now I want to set my common y axis for each rows e.g 1st row should have one common y values, same goes with the 2nd and 3rd rows.

I tried but not able to do it. plot is attached
I used


ggplot(data = PB, aes(x = new_date, y = Mean, group = 1))+ 
  geom_line(aes(color = experiment)) +
  theme(legend.title=element_blank()) +
  facet_wrap( ~MonthAbb,scales = "free_y", nrow = 3)

IRplot

Without a reprex of sample data it's hard to know exactly if it'll work, but have you tried adding

scale_y_continuous(limits = c(min, max))

...where min and max are the numbers you want to be top & bottom? Also think about adding breaks() with the numbers you want represented.

This might help https://ggplot2.tidyverse.org/reference/scale_continuous.html

I have shared my data here.

One option is to use a utility like ggpubr::ggarrange() / egg::ggarrange() / patchwork to combine different plots together into a single output.

So, you could take your data and filter it by MonthAbb %in% month.name[1:4] for example before doing a facet wrap. Just repeat for each set of 4 months and then arrange them all together.

Use scales = "fixed" instead of scales = "free_y" if you want all the plots to have the same y axis (the y axis labels then should not be repeated across the plots in a row).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.