Skip to content
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

Blog figure sorts months alphabetically #399

Open
toddyoder-mrg opened this issue Sep 26, 2024 · 0 comments
Open

Blog figure sorts months alphabetically #399

toddyoder-mrg opened this issue Sep 26, 2024 · 0 comments

Comments

@toddyoder-mrg
Copy link

toddyoder-mrg commented Sep 26, 2024

The patchwork 1.3.0 blog post gives an example where wrap_table() is used to align the x-axis of a figure with the columns of a table. The figure in the example sorts the months alphabetically rather than by the desired calendar order.

p2 <- ggplot(airquality) + 
  geom_boxplot(aes(x = month.name[Month], y = Temp)) + 
  theme(axis.text.x = element_blank(), axis.title.x = element_blank()) + 
  scale_x_discrete(expand = c(0, 0.5))

https://www.tidyverse.org/blog/2024/09/patchwork-1-3-0/#tables-are-figures-too:~:text=geom_boxplot(aes(x%20%3D%20month.name%5BMonth%5D%2C%20y%20%3D%20Temp))%20%2B

image

Possible solution: convert Month to factor sorted numerically.

p2 <- ggplot(airquality) + 
  geom_boxplot(aes(x = factor(Month), y = Temp)) + 
  theme(axis.text.x = element_blank(), axis.title.x = element_blank()) + 
  scale_x_discrete(expand = c(0, 0.5))
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

No branches or pull requests

1 participant