Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在ggplot2/geom_平滑中使用跨度_Html_R_Ggplot2 - Fatal编程技术网

Html 在ggplot2/geom_平滑中使用跨度

Html 在ggplot2/geom_平滑中使用跨度,html,r,ggplot2,Html,R,Ggplot2,我正在使用ggplot2创建包含多个数据集的绘图。由于并非所有数据集都有相同数量的数据点(或有断点),我想调整跨度 但我不确定span的调整会产生什么影响,它既没有记录在stat_smooth中,也没有记录在geom_smooth中,我知道在哪里可以找到span是如何从数据集获取数据的吗?span如何计算计算平滑度所需的数据点数量? 代码如下所示: t<-ggplot(data=XX1)+ scale_x_date(as.POSIXct(XX1$date1), breaks = "1 mo

我正在使用
ggplot2
创建包含多个数据集的绘图。由于并非所有数据集都有相同数量的数据点(或有断点),我想调整跨度

但我不确定span的调整会产生什么影响,它既没有记录在
stat_smooth
中,也没有记录在
geom_smooth
中,我知道在哪里可以找到span是如何从数据集获取数据的吗?span如何计算计算平滑度所需的数据点数量? 代码如下所示:

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 Ten Minutes / Day \n",
             x = "\n Year (August 2012 - March 2014",
             y = "% DP10M per Day \n"))
t

t请做一个可复制的简短示例

此几何图形的默认统计是
stat\u smooth

在阅读stat_smooth帮助(?stat_smooth)后,该函数使用stats base软件包中lm、glmor函数的统计方法。gam方法有一个mgcv包的参考。因此,stat_smooth的span参数使用这些方法来控制平滑度

但验证这一点的简单方法是使用stats包的loessfunction,并与使用stat_smooth获得的结果进行比较

在本例中,semm的结果相同:

黄土:

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)

period多亏了它的帮助,span在黄土{stats}中被定义为alpha:“对于α<1,邻域包括点的比例α,并且这些点具有三次加权(与(1-(dist/maxdist)^3)^3成比例)。对于α>1,使用所有点,“最大距离”假定为α^(1/p)乘以p解释变量的实际最大距离。”
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)