Skip to content

Add an example for stat_align() #4940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022

Conversation

yutannihilation
Copy link
Member

A followup of #4889. I think the document should have one or two examples to show how stat_align() works.

devtools::load_all("~/GitHub/ggplot2/")
#> ℹ Loading ggplot2
df <- data.frame(
  g = c("a", "a", "a", "b", "b", "b"),
  x = c(1, 3, 5, 2, 4, 6),
  y = c(2, 5, 1, 3, 6, 7)
)
a <- ggplot(df, aes(x, y, fill = g)) +
  geom_area()

# Two groups have points on different X values.
a + geom_point(size = 8) + facet_grid(g ~ .)

# stat_align() interpolates and aligns the value so that the areas can stack
# properly.
a + geom_point(stat = "align", position = "stack", size = 8)

Created on 2022-08-11 by the reprex package (v2.0.1)

@thomasp85
Copy link
Member

Thanks!

@yutannihilation yutannihilation merged commit cb3ba4a into tidyverse:main Aug 23, 2022
@yutannihilation yutannihilation deleted the doc/stat-align branch August 23, 2022 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants