Created
October 13, 2020 10:05
-
-
Save debruine/6b9110468649aa7f9883f04437f3a6a3 to your computer and use it in GitHub Desktop.
cowplot's plot_grid function doesn't work with labels if a custom theme has been set using theme()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
## set custom theme (even with no options) | |
theme_set(theme()) | |
## Error: Aesthetics must be either length 1 or the same as the data (1): colour and family | |
a <- ggplot(cars, aes(speed, dist)) + geom_point() | |
cowplot::plot_grid(a, a, labels = c("A", "B")) | |
## Works with no labels | |
cowplot::plot_grid(a, a) | |
## Works when theme reset | |
theme_set(theme_classic()) | |
cowplot::plot_grid(a, a, labels = c("A", "B")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because the custom theme does not set the required aesthetic for
cowplot:::draw_plot_label
to use.This works:
theme_set(theme(text=element_text(colour = "black", font= "Times"))
And this works as well:
cowplot::plot_grid(a, a, labels = c("A", "B"), label_fontfamily = "Times", label_colour = "black")