ggsave cuts of part of the common legend created with ggarrange

Viewed 348

I am trying to generate multiple plots from my data by using lapply and then arranging the resulting list with ggarrange. When I try to save the final figure with ggsave part of the legend text is cut off in the png.

First I define what I want to plot along with Plot titles and colors

main.overview <- list(
          c("AA", "AA", "black"),
          c("X5.HETE", "5-HETE", "red"),)

I then define a function to generate the plots.

plot.overview = function(data, mediator) {
analyte <- mediator[[1]]
name  <- mediator[[2]]
color <- mediator[[3]]
ggplot(data = data, aes_string(x="Compound",y=analyte)) +
    geom_boxplot(aes(fill=Compound)) +
    labs(title=name) +
    scale_fill_brewer(palette="Reds") +
    theme_classic() +
    theme(plot.title = element_text(hjust = 0.5, color = color),axis.title.x = element_blank(),axis.title.y = element_blank())}

Finally I call the function and arrange the plots into a figure

myplots <- lapply(main.overview, plot.overview, data=lm)
arrange <- ggarrange(plotlist = myplots, common.legend = TRUE, nrow=1, legend = "right")
figure <- annotate_figure(arrange, left = text_grob(expression(10^6~cells), rot=90))
ggsave("overview.png", dpi="print", device="png",plot=figure, height=10, width=30, units="cm")

In the final png however the common legend i put on the right is cut off.

EDIT: I have figured out part of the problem, the problem only occurs on my desktop-pc and not on my laptop, so it might be a problem with additional packages or versions of the R libraries

0 Answers
Related