When following the tutorial to add logos to a ggplot, I noticed that the added image is only visible when the ggplot you create uses the cowplot::theme_half_open or you specify blank background themes. In the example below, you cannot see the logo when you use the default ggplot2 theme (as seen in p2). Would it be possible to apply the necessary theme changes when draw_plot is called so this functionality works with ggplot out of the box?
library(ggplot2)
library(cowplot)
logo_file <- system.file("extdata", "logo.png", package = "cowplot")
cow <- ggdraw() +
draw_image(
logo_file, scale = .7
)
# Example from tutorial
p1 <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha = 0.7) +
scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
theme_half_open(12)
# Make plot with no changes to theme.
p2 <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha = 0.7) +
scale_y_continuous(expand = expansion(mult = c(0, 0.05)))
# Remove background theme.
p3 <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha = 0.7) +
scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
theme(
plot.background = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank(),
legend.background = element_blank()
)
# Works as it does in the tutorial
cow + draw_plot(p1)
When following the tutorial to add logos to a
ggplot
, I noticed that the added image is only visible when theggplot
you create uses thecowplot::theme_half_open
or you specify blank background themes. In the example below, you cannot see the logo when you use the defaultggplot2
theme (as seen inp2
). Would it be possible to apply the necessary theme changes whendraw_plot
is called so this functionality works withggplot
out of the box?Created on 2023-05-23 with reprex v2.0.2