rdata <- c(
0.00000000,0.09370000,0.37500000,0.84370000,1.50000000,2.34370000,3.37500000,
4.59370000,5.99990000,7.59360000,9.37490000,11.34360000,13.49980000,15.84350000,
18.37480000,21.09350000,23.99970000,27.09340000,30.37460000,33.84330000,37.49950000,
0.09376236,0.37504944,0.84371981,1.49991490,2.34377614,3.37502067,4.59364849,
5.99994246,7.59361972,9.37482170,11.34354841,13.49979982,15.84357596,18.37473539,
21.09341955,23.99962842,27.09336201,30.37462031,33.84326192,37.49956966
)
fitted <- c(
0.000000e+00,5.753386e-05,9.215290e-04,4.664786e-03,1.474561e-02,3.600278e-02,
7.467473e-02,1.383905e-01,2.362147e-01,3.786691e-01,5.778025e-01,8.472223e-01,
1.202270e+00,1.660126e+00,2.240041e+00,2.963485e+00,3.854605e+00,4.940527e+00,
6.251861e+00,7.823289e+00,9.694269e+00,5.761047e-05,9.217720e-04,4.665005e-03,
1.474393e-02,3.600511e-02,7.467565e-02,1.383874e-01,2.362180e-01,3.786710e-01,
5.777928e-01,8.472146e-01,1.202270e+00,1.660142e+00,2.240025e+00,2.963462e+00,
3.854581e+00,4.940513e+00,6.251870e+00,7.823270e+00,9.694307e+00
)
plot(rdata,fitted,'l')
当我在类型'l'中绘制数据时,会出现一条直线和一条曲线。曲线是我的预期。但是直线排列起始值和结束值,这很奇怪。任何人都可以帮我删除那条线吗?
答案 0 :(得分:1)
首先,将数据放入矩阵中:
mat <- cbind(rdata, fitted)
然后,根据rdata
列重新排序矩阵:
mat2 <- mat[order(mat[,1]),]
现在,情节应该可以正常工作:)
plot(mat2, typ="l")
编辑:这是你想要的传奇吗?我不太明白,因为你只画了一条线,我假设它是“拟合”线 - 观测数据的x-y坐标是什么?
legend("topleft", legend=c("Observed", "Fitted"), lty=c(NA, 1), pch=c(19, NA))
以下是生成的图: