[英]ggplot2: Transparent legend background when stat_smooth is used
I have two plots. 我有两个情节。 One with smoothed lines:
一条线条平滑:
library(splines)
library(ggplot2)
ggplot(mtcars, aes(hp, qsec)) + stat_smooth(aes(group = cyl,
colour = factor(cyl)),
method = "glm",
formula = y ~ ns(x, 1),
level = 1e-9,
size = I(1)) +
theme(panel.background=element_rect(fill="transparent",colour=NA),
plot.background=element_rect(fill="transparent",colour=NA),
legend.key = element_rect(fill = "transparent", colour = "transparent"))
and one without: 一个没有:
ggplot(mtcars, aes(hp, qsec)) +
geom_point(aes(group = cyl, colour = factor(cyl))) +
theme(panel.background=element_rect(fill="transparent",colour=NA),
plot.background=element_rect(fill="transparent",colour=NA),
legend.key = element_rect(fill = "transparent", colour = "transparent"))
How can I get a white or transparent legend background in the first plot? 如何在第一个图中获得白色或透明的图例背景? And why do the same theme-commands do the job in the second plot?
为什么相同的主题命令在第二个绘图中完成工作?
It seems like the grey background is coming from stat_smooth()
, as explained here . 这似乎是灰色的背景是来自
stat_smooth()
如解释在这里 。 Adding se=FALSE
, which deactivates the confidence intervals, seems to fix it: 添加
se=FALSE
会停用置信区间,似乎可以修复它:
ggplot(mtcars, aes(hp, qsec)) + stat_smooth(aes(group = cyl,
colour = factor(cyl)),
method = "glm",
formula = y ~ ns(x, 1),
level = 1e-9,
size = I(1),
se = FALSE) +
theme(panel.background=element_rect(fill="transparent",colour=NA),
plot.background=element_rect(fill="transparent",colour=NA),
legend.key = element_rect(fill = "transparent", colour = "transparent"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.