Plot a 3D linear surface from 2D functions in R -


i have following data:

x <- c(1000,2000,3000,4000,5000,6000,8000,12000)  y_80 <- c(33276,33276,5913,2921,1052,411,219,146) y_60 <- c(14724,14724,3755,1958,852,372,211,140) y_40 <- c(9632,9632,2315, 1250,690,332,196,127) y_20 <- c(4672,4672,1051,562,387,213,129,81) y_5  <- c(825,825,210,118,88,44,27,17) 

from data create 5 spline functions:

f_80 <- splinefun(x, y_80, method=c("monoh.fc")) f_60 <- splinefun(x, y_60, method=c("monoh.fc")) f_40 <- splinefun(x, y_40, method=c("monoh.fc")) f_20 <- splinefun(x, y_20, method=c("monoh.fc")) f_5 <- splinefun(x, y_5, method=c("monoh.fc")) 

the z axle number after f_ i.e. function f_80 z value 80 , on.

what needed plot 3d surface functions, linear interpolation between lines. possible in r? have similar questions can't find answer. thanks

there variety of r pseudo-3d plotting functions. base-graphics has persp, , wireframe in lattice, , coolest of all, surface3d in rgl. differ in how handle axis arguments accept matrix argument z-values. `persp simplest:

 z_80 <- f_80(x)  z_60 <- f_60(x)  z_40 <- f_40(x)  z_20 <- f_20(x)  z_5  <- f_5(x)    png(); persp(matrix(c(z_80, z_60, z_40, z_20, z_5 ), nrow=length(x),                dimnames= list(x=x, y=c(80,60,40,20,5) ) ) )   dev.off() 

enter image description here

you might find using ticktype="detailed" more informative:

 png(); persp(matrix(c(z_80,z_60,z_40,z_20,z_5 ), nrow=length(x),                        dimnames=list(x=x, y=c(80,60,40,20,5) ) ) ,                        ticktype="detailed", xlab="x axis", ylab="y axis",                        zlab=".                z= f(y)", theta=45) ; dev.off() 

i need play viewing angle theta like. getting z-axis label move away long z-tick-labels hack.

enter image description here


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -