remove legend in ggplot in r

To remove the legend in ggplot2 in R, you can use the following code:

main.r
+ theme(legend.position = "none")
34 chars
2 lines

This will remove the legend from the plot. Here's a full example:

main.r
library(ggplot2)

ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) + 
  geom_point() + 
  theme(legend.position = "none")
131 chars
6 lines

Alternatively, you can also use legend.none() or element_blank() to remove the legend:

main.r
+ theme(legend.position = "none") 
# or
+ theme(legend = element_blank())
74 chars
4 lines

related categories

gistlibby LogSnag