Reputation: 15286
I'm using qplot to plot a function and I want to position the legend within the plot. I've used
opts( legend.position = c(0.7,0.7) )
to move the legend where I want it to be.
However there is a white border around the legend and that shows up on the gray background.
For example:
library(ggplot2)
x = c(1:20)
y = c(1:20)
p <- qplot(x,y, color = "blue")
p <- p + scale_colour_identity("Example", breaks=c("blue"), labels=c("dots"))
p <- p + opts(legend.position = c(0.6, 0.4))
print(p)
I would like to know how to remove this border from the legend. Thank you.
Upvotes: 4
Views: 18519
Reputation: 3017
For newer version of ggplot
, opts
is replaced by theme
& theme_rect
is replaced by element_rect
p + theme(legend.background = element_rect(color = NA))
This will get rid of your border:
p + opts(legend.background = theme_rect(col = 0))
other options in addition to col (which applies to the border) are fill (background) and size (which is the border size).
Hope that helps!
All the best,
Jay
Upvotes: 6