r - How to position the plot legend outside the plot in the bottom-right -
i'm using latest ggplot2 , p + theme(legend.position='right'). function theme documented , combining bottom , right doesn't seem possible. however, maybe there alternate way achieve this?
you can use 2-element numeric vector position, like:
p+theme(legend.position=c(0.85,0) the problem is, overlap plotting area.
and if want force in 1 horizontal line, can add:
p+guides(fill = guide_legend(nrow = 1)) edit
i used plot.margin expand area @ bottom, can play parameters:
p+ guides(fill = guide_legend(nrow = 1))+ theme(plot.margin=unit(c(1,1,4,0.5),"cm"))+ theme(legend.position=c(0.85,-0.7)) or
p+ theme(plot.margin=unit(c(1,1,4,0.5),"cm"))+ theme(legend.position=c(0.85,-0.7) )
note
using rstudio, when export image @ width*height don't legends, if drag , adjust view before exporting follows, works.




Comments
Post a Comment