ggplot2
ggplot2 copied to clipboard
Feat/issue 4899 simplify alignment for column geoms
This PR adds a just
argument to geom_col()
and geom_bar()
(#4899) allowing a user to more easily change the alignment of columns. In particular, it makes it easy to align the sides of columns with axis breaks in cases where the resolution()
of the data is not trivial to calculate.
-
just
is used rather thanhjust
. This has a downside that it breaks with thehjust
/vjust
pattern used elsewhere in ggplot2, however it seems preferable sincehjust
would necessitatevjust
for horizontal columns, which would raise difficult questions about whether to modify other behaviour, e.g. ofhas_flipped_aes()
. - There is a small improvement to the documentation for the
width
argument - resolution of the data now reads asresolution()
of the data to more clearly hint at what's happening under the hood - This PR does not (as yet) include the extra aesthetics
xmin
andymin
forgeom_col()
Here's how to use the just
argument:
devtools::load_all()
#> i Loading ggplot2
df <- data.frame(
x = 1:3,
y = 1:3
)
ggplot(df, aes(y, x)) +
geom_col(just = 1)
Created on 2022-07-26 by the reprex package (v2.0.1)
Thanks. Could you avoid using the Windows line ending? If you are using RStudio, you can set it here (you might also need to review your Git settings as Git might convert the line endings on committing).
Thanks. Could you avoid using the Windows line ending? If you are using RStudio, you can set it here (you might also need to review your Git settings as Git might convert the line endings on committing).
Thanks, done now. I was puzzling about why the diff was showing all files as changed!
Thanks, looks almost good. Random comments:
- I think we should add at least one example to show how just works briefly.
- When used with some positions (e.g.
position_dodge()
), non-default just might result in a bit weird look. I'm wondering if we can add some friendly note about this.
Both of these are now complete. The friendly note is in the documentation for the just
argument itself, but may be more appropriate in the example. Not a big deal either way though 😄 Thanks!
Do you think the whole
setup_data
field forgeom_col()
andgeom_bar()
should have its own named function (e.g.setup_col_data()
) to avoid code duplication btw?
I can't remember the reason why GeomBar
and GeomCol
are implemented separately, but, as now they are just duplicate. There's a plan to remove it (https://github.com/tidyverse/ggplot2/issues/3798), but, for now, could you just leave them duplicate? I think we should do one by one..
LGTM
Thanks for reviewing!