Span argument not working on graph on ggplot2

2019-08-23 02:45发布

I have a plot and I wanted to change the span argument, but I don't see a difference in my lines.My observations are more than 1000 in each of the data.

I used this code:

ggplot(data, aes(x=, y=)) + geom_smooth(aes(color="KHRC"),se = FALSE, span = 0.3)+
  geom_smooth(data=GO1,aes(color="GO1"),se = FALSE, span = 0.3)+
  geom_smooth(data=GO2,aes(color="GO2"),se = FALSE, span = 0.3)+
  geom_smooth(data=GO4,aes(color="GO4"),se = FALSE, span = 0.3)+
  geom_smooth(data=GO3,aes(color="GO3"),se = FALSE, span = 0.3)+
  geom_smooth(data=GO6,aes(color="GO6"),se = FALSE, span = 0.3)+
  scale_x_datetime(limits = c(ymd_hms("2016-11-05 09:00:00"), ymd_hms("2016-11-07 00:00:00")))+
  labs(color="ID")+
  ggtitle("x vs y ")

Suggestions on how to fix the span will be great.Thank you.

标签: r ggplot2
1条回答
可以哭但决不认输i
2楼-- · 2019-08-23 03:17

Here is a simple, reproducible example of geom_smooth using the span parameter with the built-in iris dataset. This may help get you started troubleshooting your own implementation. As you can see below, changing the span from 0.5 to 0.95 functions as expected. Unfortunately it is not clear why it's not working for you, because we don't have your dataset to test it out.

library(ggplot2)

p1 = ggplot(iris, aes(x=Sepal.Width, y=Sepal.Length, colour=Species)) +
     geom_point(size=2, alpha=0.5, shape=20) +
     geom_smooth(method="loess", se=FALSE, span=0.5) +
     labs(title="Span = 0.5")   

p2 = ggplot(iris, aes(x=Sepal.Width, y=Sepal.Length, colour=Species)) + 
     geom_point(size=2, alpha=0.5, shape=20) +
     geom_smooth(method="loess", se=FALSE, span=0.95) +
     labs(title="Span = 0.95")

library(gridExtra)
ggsave("geom_smooth.png", arrangeGrob(p1, p2, ncol=2), width=9, height=4, dpi=150)

enter image description here

查看更多
登录 后发表回答