如何在使用theme_bw时删除ggplot2图例中各个条目周围的灰色边框?

Gim*_*ist 6 r legend ggplot2

我在R中有以下代码:

library(ggplot2)
theme_set(theme_bw())
p <- ggplot(mtcars, aes(wt, mpg))
p <- p + geom_point(aes(colour = factor(cyl)))
p
Run Code Online (Sandbox Code Playgroud)

结果如下:

传奇中的ggplot2灰色边框

每个图例条目周围都有一个灰色边框.如何删除它?

ton*_*nov 17

只需添加

+ theme(legend.key = element_rect(colour = NA))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述