使用curve3D绘制表面三维图中的数据点

时间:2015-11-20 16:52:25

标签: r 3d surface

我创建了一个表面3D图,如下所示:

library(emdbook)
params <- c(a0=2.378735e+02,a1=-3.295241e-03, a2=-7.878536e+02, a3=-1.518790e-01, p0=380.0814,p1=-0.000664)
Age<- as.matrix(seq(0:350)) 
Preci<-as.matrix(seq(from=10, to=3000, by=8))

curve3d(with(as.list(params),
             (a0*(exp(a1*Age))+a2*(exp(a3*Age)))+
               ((p0*(1-exp(p1*Preci))))),
        varnames=c("Age","Preci"),
        xlim=c(0,350),ylim=c(500,3000),
        sys3d="persp",
        xlab = "Stand Age", ylab = "Annual precipitation", zlab = "NEP",
        phi = 25, theta = 35, lwd=0.2)

我现在想在表面图上绘制我的真实数据。这是我的真实数据。

    df<-structure(list(Age = c(97, 100, 101, 301, 302, 74, 75, 77, 78, 
79, 49, 50, 51, 52, 53), Precipitation = c(1241.59999960661, 
1282.40000277758, 1159, 895, 1106, 960.399999260902, 988.300011262298, 
778.211069688201, 743, 676.725008800626, 1750.51986303926, 1614.11541634798, 
951.847023338079, 1119.3682884872, 1112.38984390156), NEP = c(304.238143564202, 
569.328627431765, 331.042528439313, 739.620045015588, 220.96392728202, 
152.264522056852, 90.1433769206633, 14.9873599316925, 234.736409910023, 
60.4167695627548, 380.654850683175, 467.840079978108, 358.497598990798, 
431.528439198621, 442.010991849005)), .Names = c("Age", "Precipitation", 
"NEP"), row.names = 919:933, class = "data.frame")

任何人都知道怎么做?

1 个答案:

答案 0 :(得分:0)

test<-curve3d(with(as.list(params),
             (a0*(exp(a1*Age))+a2*(exp(a3*Age)))+
               ((p0*(1-exp(p1*Preci))))),
        varnames=c("Age","Preci"),
        xlim=c(0,350),ylim=c(500,3000),
        sys3d="persp",
        xlab = "Stand Age", ylab = "Annual precipitation", zlab = "NEP",
        phi = 25, theta = 35, lwd=0.2)

persp(test$x, test$y, test$z, phi = 25, theta = 35, lwd=0.2,xlab = "Stand Age", ylab = "Annual precipitation", zlab = "NEP",
      xlim=c(0,350),ylim=c(100,3000))->res

points(trans3d(df$Age, df$Precipitation, df$NEP, pmat = res), col="black", bg=1, pch=15, lwd=0.01)