简体   繁体   中英

Plotting only stat_smooth without original ggplot2 data

I plot data with ggplot, and I wanted to see the smoothed lines using stat_smooth.
But now I would like to only plot the smoothed lines (somehow extract it), without the original 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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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