patchwork
patchwork copied to clipboard
Blog figure sorts months alphabetically
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
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))