I have two ggplots (boxplots) I want to be aligned in one graph, but I'm facing a problem : see the problem here. Indeed, my two x-axis aren't aligned and I don't know how to change it. I'm just doing a grid.arrange(p1, p2, ncol = 2, nrow = 1)
Asked
Active
Viewed 52 times
0
-
This might help https://stackoverflow.com/questions/48164435/merge-and-perfectly-align-histogram-and-boxplot-using-ggplot2/48164920#48164920 – Tung Mar 19 '21 at 17:14
-
This would be easier to answer if you included the code used to create the boxplots – Conor Neilson Mar 19 '21 at 22:26
-
@ConorNeilson yes of course, sorry, here it is : `bp_al <- ggplot(al, aes(x = Subst, y = Concentration)) + geom_boxplot(fill = "blue", width = 0.5) + theme_minimal() + xlab("") + ylab("") + theme(axis.text.x = element_text(angle = 0, size = 8), axis.text.y = element_text(color = "blue", size = 7)) + theme(plot.margin=unit(c(0,-0.3,0,-0.5), "cm")) + scale_y_continuous(breaks = seq(0, 30000, 9500)) + scale_x_discrete(expand = c(0.8, 0))` and same for the other one – sholuara Mar 20 '21 at 19:24
-
@Tung thank you! i've tried this but i think that the problem comes from my graphs, the x axis is higher in one graph, automatically... i don't know how to fix it – sholuara Mar 20 '21 at 19:37
-
You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to quickly create a reproducible example so others can help. Please do not use `str()`, `head()` or screenshot. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Mar 21 '21 at 07:21