Black panel when I save a plot generated with cowplot

Viewed 120

I have a plot with 3 panels and a legend in its own panel, when I visualize it is ok but when I save it the panel with the legend becomes black!

library(ggplot2)
library(cowplot)
df <-data.frame(a=seq(1,20),b=seq(1,20), c=as.factor(c(rep("A", 10),rep("B",10))))
O <- ggplot(df, aes(x = a, y = b)) + geom_point(aes(col=c))
legend <- get_legend(O)

A <- ggplot(df, aes(x = a, y = b)) + geom_point(aes(col=c), show.legend = F)
B <- ggplot(df, aes(x = c, y = b)) + geom_boxplot(aes(col=c), show.legend = F)



lol <- plot_grid(A, B, C,legend,
                 nrow=2, 
                 align="hv", rel_widths = c(1, 1, 1, 1, 1, 1),
                 labels = c('A', 'B', 'C', 'D', 'E', ''))
lol
save_plot("lol.png",lol,base_width=8,base_height=6,dpi=600)

enter image description here

0 Answers
Related