ggpattern
ggpattern copied to clipboard
New "stackdodge" position
-
A new
{ggplot2}"position" that does both a "dodge" and "stack" might be useful:- https://github.com/coolbutuseless/ggpattern/issues/67
-
Technically this seems like this should be implemented as a new
{ggplot2}"position" class:- https://ggplot2-book.org/extensions.html#new-positions
-
Not necessarily useful just for
{ggpattern}(i.e. people seem to want to do this with unpatterned basegeom_bar()):- https://stackoverflow.com/questions/46597278/how-to-plot-a-stacked-and-grouped-bar-chart-in-ggplot/46597859#46597859
-
Would
{ggpattern}be the right level to implement this? Five years ago{ggplot2}maintainers said they had no (near-term) plans on implementing this particular "position" themselves: https://github.com/tidyverse/ggplot2/issues/2267- But what if they received a PR that implemented this?
{ggplot2}did add a "jitterdodge" position so perhaps "stackdodge" would be the appropriate name...
Also note one can achieve a similar affect via facet_grid():
library(ggplot2)
library(ggpattern)
df <- transform(mpg, cyl = as.factor(cyl))
ggplot(df, aes(x = cyl)) +
facet_grid(. ~ class) +
geom_bar(aes(fill = cyl)) +
geom_bar_pattern(aes(pattern = drv),
fill = "transparent", col = "black",
pattern_spacing = 0.2, pattern_density = 0.4,
pattern_key_scale_factor = 0.2) +
scale_pattern_manual(values = c("none", "stripe", "circle"))
