Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Legend box out of boundary when saving with ggsave()

I've placed my legend horizontally (5 categories) below my barpchart, within r this works fine, but when I save my plot as a picture some categories from the legend disappear or are out of boundary of the plot/picture. I used ggsave("myPlot.png", p, units = "cm", dpi = 600) in which p represents my plot. Should I fix this within my ggplot call or within ggsave() and how? I want a smaller length of the complete legend box (in the final saved picture). I've included the picture, so you can see how the legend went wrong. Help is appreciated! Thank you.

enter image description here

like image 746
Benjamin Telkamp Avatar asked Sep 03 '25 08:09

Benjamin Telkamp


1 Answers

save_plot() from the cowplot package avoids this

instead of:

ggsave("myPlot.png", p)

try:

save_plot("myPlot.png", p)

like image 145
talialynn Avatar answered Sep 04 '25 23:09

talialynn