简体   繁体   English

仅绘制stat_smooth而不绘制原始ggplot2数据

[英]Plotting only stat_smooth without original ggplot2 data

I plot data with ggplot, and I wanted to see the smoothed lines using stat_smooth. 我用ggplot绘制数据,我想使用stat_smooth查看平滑线。
But now I would like to only plot the smoothed lines (somehow extract it), without the original ggplot. 但是现在我只想绘制平滑线(以某种方式提取),而没有原始ggplot。
Do you think it's possible? 你认为有可能吗?

Here is my code : 这是我的代码:

Graph <- ggplot(data=Forecasttemp, aes(x=Price.date, y=Price, colour=Group)) + geom_line() + scale_colour_hue(guide = "none")
Graph <- Graph + stat_smooth(se = FALSE,  aes(fill = Group)) + scale_colour_hue(guide = "none")

If you want to plot only the smoothed lines without original sample points, you can simply omit geom_line(), thus resulting in: 如果只想绘制没有原始采样点的平滑线,则可以简单地省略geom_line(),从而得到:

Graph <- ggplot(data=Forecasttemp, aes(x=Price.date, y=Price, colour=Group)) +
         stat_smooth(se = FALSE,  aes(fill = Group)) + 
         scale_colour_hue(guide = "none")

Unfortunately I can not try this due to the lack of a reproducible example, but I make a try with an R base dataset and it worked: 不幸的是,由于缺少可重现的示例,我无法尝试此操作,但是我尝试使用R基本数据集进行了测试:

library(ggplot2)
data(iris)
g1 <- ggplot(data=iris, aes(x=Sepal.Length, y=Petal.Length, colour=Species)) + 
      scale_colour_hue(guide = "none") + geom_smooth()
g1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM