如何在 ggplot2 中绘制 "geom_smooth" 时删除 SE 上的填充区域?
How to remove filled area on SE when plot "geom_smooth" in ggplot2?
我想在 ggplot2 中绘制 geom_smooth()
没有填充 se
,但只有 se.
的两个边缘
我已经尝试使用代码 geom_smooth(method="loess", se=T, fill=NA)
,但它没有达到我的预期。
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(size=2)+
geom_smooth(method = "loess", se=T)
解决方案:
gg <- ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth(fill = "transparent")
ggg <- ggplot_build(gg)
dat <- ggg$data[[2]]
gg + geom_line(aes(x, ymin), data=dat, linetype="dashed") +
geom_line(aes(x, ymax), data=dat, linetype="dashed")
可能是这样的?两端竖线跳过失败
library(ggplot2)
ggplot(data = mtcars,
mapping = aes(x = wt,
y = mpg)) +
geom_point(size = 2) +
geom_smooth(method = "loess",
se = FALSE,
colour = "black") +
geom_ribbon(stat = "smooth",
method = "loess",
se = TRUE,
alpha = 0, # or, use fill = NA
colour = "black",
linetype = "dotted")
我想在 ggplot2 中绘制 geom_smooth()
没有填充 se
,但只有 se.
我已经尝试使用代码 geom_smooth(method="loess", se=T, fill=NA)
,但它没有达到我的预期。
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(size=2)+
geom_smooth(method = "loess", se=T)
解决方案:
gg <- ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth(fill = "transparent")
ggg <- ggplot_build(gg)
dat <- ggg$data[[2]]
gg + geom_line(aes(x, ymin), data=dat, linetype="dashed") +
geom_line(aes(x, ymax), data=dat, linetype="dashed")
可能是这样的?两端竖线跳过失败
library(ggplot2)
ggplot(data = mtcars,
mapping = aes(x = wt,
y = mpg)) +
geom_point(size = 2) +
geom_smooth(method = "loess",
se = FALSE,
colour = "black") +
geom_ribbon(stat = "smooth",
method = "loess",
se = TRUE,
alpha = 0, # or, use fill = NA
colour = "black",
linetype = "dotted")