你建议的命令在某种程度上达到了目的但是我仍在寻找一个命令/功能来提供更平滑的曲线。我正在给出一个可重现的代码,它正在绘制相当尖锐的边缘或更粗糙:连接点的线太尖锐,特别是在它从一个点开始到另一个点的那一刻。很抱歉非技术语言,因为我仍然不熟悉该领域。感谢您提供有关此问题的帮助。请在下面的代码中建议修改以获得更平滑的曲线。
xdata1<-c(6:11)
ydata1<-c(-0.75132894, -1.71909555, -0.62653171, 0.49512191, 0.29201836, 0.31094460)
plot(NULL,NULL,xlim=xlims,ylim=ylims,axes=FALSE, ann=FALSE)
axis(1,cex.axis=0.7,mgp=c(3, .3, 0))
axis(2, las=1,cex.axis=0.7,at=c(-2,-1,0,1,2), mgp=c(3, .7, 0))
mtext(side = 1, text =expression('Year'), line = 1,font=15)
mtext(side = 2, text = expression('Variable'), line = 1.5,font=15)
lines(smooth.spline(xdata1,ydata1, df=5), col='red',type="l", pch=22, lty=1, lwd=1)
#######更新查询完成此处
我必须根据1的时间步长绘制非常小的幅度数据。请参阅下面的示例数据:
xdata<-c(1:48)
ydata<- c(0.325563413,0.401913414,0.221939845,0.19881055,
-0.05918293,-1.108143815,-0.220563332,-0.148715078,
-0.14998762,0.131610695,0.249923598,0.246891873,
0.656812019,0.524436114,0.23875397,0.200695075,
-0.015974087,-0.611863249,0.121994831,-0.143103421,
-0.142109609,0.101451935,0.160242421,0.232404601,
0.348305745,0.231109382,0.334988321,0.263046902,-0.058154333,
-1.032276818,-0.352068888,-0.13082767,-0.134611511,0.116967421,
0.268706409,0.232776855,0.39515544,0.540317537,0.424281195,
0.3061158,-0.210735495,0.023705618,0.473338271,0.270527033,
-0.165394174,0.268773501,0.202437269,0.305577906)
请帮我绘制平滑线,而不突出显示数据的各个点。
提前致谢,
答案 0 :(得分:5)
不确定“没有突出显示个别点”意味着什么,但这是获得平滑线的一种方法:
plot(xdata,ydata)
lines(smooth.spline(xdata,ydata, df=10), col = "red")
另请参阅:?loess.smooth
,apropos("smooth")
。搜索“[r] smooth plot”找到How to fit a smooth curve to my data in R? ...
答案 1 :(得分:0)
在图中指定类型为“l”只会给你一行。
plot(xdata, ydata, type = "l")