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)) 

output

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)) 

enter image description here

or

  p+      theme(plot.margin=unit(c(1,1,4,0.5),"cm"))+      theme(legend.position=c(0.85,-0.7) 

)

enter image description here

note

using rstudio, when export image @ width*height don't legends, if drag , adjust view before exporting follows, works.

enter image description here


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -