Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2 avoid boxes around legend symbols

Tags:

r

ggplot2

Consider the example plot below. I'd like to make the little boxes around each of the symbols in the legend go away. How an I do this?

 ggplot(mtcars, aes(wt, mpg, shape=factor(cyl))) + geom_point() + theme_bw() 

like image 874
cboettig Avatar asked Jun 29 '12 23:06

cboettig


People also ask

How do I remove a box from a legend in R?

Therefore, we can use bty="n" with the legend function and it will remove the border of the legend.

What does %>% do in Ggplot?

%>% is a pipe operator reexported from the magrittr package. Start by reading the vignette. Adding things to a ggplot changes the object that gets created. The print method of ggplot draws an appropriate plot depending upon the contents of the variable.


1 Answers

You're looking for:

 + opts(legend.key = theme_blank()) 

You can see lots of examples of all sorts of this stuff in ?opts. I couldn't remember off the top of my head which one it was, so I just tried a few until I got it right.

Note: Since version 0.9.2 opts has been replaced by theme:

+ theme(legend.key = element_blank()) 
like image 58
joran Avatar answered Sep 21 '22 13:09

joran