gpt4 book ai didi

r - ggplot2:使用 stat_smooth 时的透明图例背景

转载 作者:行者123 更新时间:2023-12-01 19:17:56 47 4
gpt4 key购买 nike

我有两个地 block 。具有平滑线条的:

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"))

还有一个没有:

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"))

如何在第一个图中获得白色或透明的图例背景?为什么相同的主题命令在第二个图中完成工作?

最佳答案

灰色背景似乎来自 stat_smooth(),如所解释的 here 。添加 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"))

enter image description here

关于r - ggplot2:使用 stat_smooth 时的透明图例背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33292437/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com