Is there a way to remove the legend border in ggplot2?

I use qplot to build a function, and I want to place a legend in the plot. I used

opts( legend.position = c(0.7,0.7) )

to move the legend where I want it to be.

However, around the legend there is a white frame that appears on a gray background.

For instance:

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.

+3
source share
1 answer

This will get rid of your border:

p + opts(legend.background = theme_rect(col = 0))

other parameters in addition to col (which applies to the border) are fill (background) and size (which is the size of the border).

Hope this helps!

All the best

Jay

+5
source

Source: https://habr.com/ru/post/1732459/


All Articles