I am trying to combine a histogram and boxplot for visualizing a continuous variable. Here is the code I have so far
require(ggplot2) require(gridExtra) p1 =
The best solution I know is using the ggpubr package:
ggpubr
require(ggplot2) require(ggpubr) p1 = qplot(x = 1, y = mpg, data = mtcars, xlab = "", geom = 'boxplot') + coord_flip() p2 = qplot(x = mpg, data = mtcars, geom = 'histogram') ggarrange(p2, p1, heights = c(2, 1), align = "hv", ncol = 1, nrow = 2)