Is it possible to achieve a histogram with a horizontal boxplot in the ggplot2 3.3.0?
Generalized opened this issue · comments
I found that you suggest to switch to ggplot2 for horizontal figures and that the ggstance may be retired one day.
I have a concrete case that I'm not sure if it's possible to achieve with ggplot2.
I need a histogram with a boxplot below. It's not about just "coord_flip". I don't want to flip everything (both histogram + boxplot), but only the boxplot.
Using your precious package it's easy to achieve this way:
g <- ggplot(....) +
geom_histogram(aes(y = ..count..)) +
facet_grid(A ~ B)
# automated searching for a good position for the boxplot
gb <- ggplot2::ggplot_build(g)
boxplot_pos <- 0.1*max(gb$data[[1]]$count)
g + ggstance::geom_boxploth(aes(y = -boxplot_pos), width = boxplot_pos, color = "slateblue", lwd = .8, alpha = .2, outlier.color = NA, coef = 1)
with the following result:
Can I achieve the same in ggplot2?
If it's not possible, kindly please consider not retiring ggstance yet. Histogram without a boxplot is so poor...
Please note, that the boxplot is an integral part of the histogram now. It works with faceting. I already saw solutions with combined separate graphs.
https://stackoverflow.com/questions/4551582/combination-boxplot-and-histogram-using-ggplot2
But this doesn't work with faceting and looks ugly. It seems that only your package can do that without much efforts, combining graphs and writing kilobytes of code. Actually, I could even skip the automated positioning and fix the "boxplot_pos" manually, making it even simpler. For this very reasons please at least keep this package active on the CRAN.