Using this as an example,
library(ggplot2)
p <- ggplot(mtcars, aes(x = disp, y = hp, color = factor(cyl))) +
geom_point() +
geom_line()
The following seems to work:
p + theme(
legend.text = element_text(color = "white"),
legend.title = element_text(color = "white"),
legend.key = element_rect(fill = "white")
) +
scale_color_discrete(
guide = guide_legend(override.aes = list(color = "white"))
)
Notice that the dimension of the gray plot area did not change.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…