Closed matanhakim closed 1 year ago
{ggpattern}
does any "dodge" calculations of its own but simply uses the positions given to it by {ggplot2}
. If we modify your "normal" geom_col()
plot and only swap geom_col()
for geom_col_pattern()
then we get the exact same arrangement of columns. The weird behavior seems to have something to do with addition of the the pattern_density
aesthetic. This somehow triggers {ggplot2}
to give us a different arrangement of columns. Perhaps this could be considered a bug on the {ggplot2}
side of things?:df_bug %>%
ggplot(aes(reason_5, pct, fill = year)) +
geom_col_pattern(position = "dodge") +
geom_text(aes(label = paste0(round(pct * 100, digits = 1), "%")), vjust = -0.5, position = position_dodge(width = 1)) +
scale_y_continuous(labels = label_percent(), expand = expansion(mult = c(0, 0.2))) +
facet_wrap(vars(gil_3), scales = "free_x", ncol = 1)
Thanks for the answer!
I'm not familiar enough with {ggplot2}
structure, how can you tell if it's a problem in {ggplot2}
or in {ggpattern}
?
If you're sure it's in {ggplot2}
, I'll file an issue over there.
Additionally, now that you mention it, this might have come up after installing the newest version of the {tidyverse}
, which possibly resulted in a new version of {ggplot2}
.
how can you tell if it's a problem in
{ggplot2}
or in{ggpattern}
If you can trigger this column flip purely in {ggplot2}
by adding and manipulating another aesthetic in geom_col()
(perhaps the border line type, color, width etc.) then you could confirm it lies with {ggplot2}
in a reproducible fashion for them to fix.
If you look in the source code of {ggpattern}
then geom_col_pattern()
calls GeomColPattern
calls GeomBarPattern
calls GeomRectPattern
calls GeomRect
{ggproto}
objects. Nowhere do {ggpattern}
create and use its own "Position" {ggproto}
objects or calculate for itself where the polygons we are going to be filling are placed in the charts. For example if you search the code for "dodge" you'll observe that there are zero "dodge" calculations being made in {ggpattern}
.
But perhaps there is a subtle difference in how {ggplot2}
currently constructs GeomCol
and how {ggpattern}
constructs GeomColPattern
that was introduced after @coolbutuseless originally forked {ggplot2}
a couple of years ago to make {ggpattern}
and this subtle difference in parameters makes a difference in this one edge case... I guess you'd need to be keeping a very close track of all the low-level commits being made upstream in {ggplot2}
. The {ggpattern}
maintainers have not been doing this...
You are correct - the bug is in {ggplot2}
itself.
I've filed an issue for {ggplot2}
here, you can see the reprex and how it's using only {ggplot2}
.
Thanks a lot for the help, this issue can be closed.
Hi, thanks a lot for this package! This is my first time issuing a bug reprot, so please inform me if anything is missing.
Bug description
I'm using ggpattern and having a weird bug: in some plots, two geom_col_pattern are switching places. This happens only in some plots, and only in one place in each of these bad plots. when I run the same code but with geom_col rather than geom_col_pattern there is no problem. Watch for the lowest-left pair of columns - in the first plot they are wrongly switched, and in the second plot they are fine.
Minimal, reproducible example
Created on 2023-03-04 with reprex v2.0.2
Session info
Please enter here the results of
xfun::session_info("ggpattern")