html - Working with span in ggplot2 / geom_smooth -
html - Working with span in ggplot2 / geom_smooth -
i using ggplot2
create plot several info sets. not datasets have same amount of datapoints (or have breaks), adjust span.
but not sure effects adjustment of span have, neither documented in stat_smooth
nor in geom_smooth
, thought can find how span taking info dataset? how span calculate number of datapoints have taken calculating smoother? code looks this:
t<-ggplot(data=xx1)+ scale_x_date(as.posixct(xx1$date1), breaks = "1 month", labels=date_format("%b %y"))+ geom_vline(xintercept=as.numeric(xx2$day.of.action, colour="lightgray"))+ geom_point(aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit) ))+ geom_smooth(data=1_f1, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=xx1, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f3, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f4, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f5, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f6, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f7, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f8, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f9, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f10, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ geom_smooth(data=1_f11, aes(x=day, y=perc_dp10m, colour=as.factor(station_subunit)),method=loess, span=0.3, se=false, lwd=1)+ theme_bw() t<-t+labs( list( title = "detection positive 10 minutes / day \n", x = "\n year (august 2012 - march 2014", y = "% dp10m per day \n")) t
any hint much appreciated!
please create short reproductible example.
the default stat geom stat_smooth
after reading stat_smooth help (?stat_smooth), function utilize statistical methods lm, glmor loess functions stats base of operations package. there alos a reference mgcv bundle gam method. so, span argument of stat_smooth utilize these methods command grade of smoothing.
but easy way verify utilize loessfunction of stats bundle , compare results obtained stat_smooth.
with this illustration results semm same:
loess:
period <- 120 x <- 1:120 y <- sin(2*pi*x/period) + runif(length(x),-1,1) plot(x,y, main="sine curve + 'uniform' noise") y.loess <- loess(y ~ x, span=0.75, data.frame(x=x, y=y)) y.predict <- predict(y.loess, data.frame(x=x)) lines(x,y.predict)
geom_smooth:
xy <- cbind(x,y) gp <- ggplot(as.data.frame(xy), aes(x=x,y=y)) + geom_point() gp + geom_smooth(aes(y=y,x=x), data=as.data.frame(xy), method = "loess", span = 0.75)
html r ggplot2
Comments
Post a Comment