简体   繁体   中英

How do I plot3d a locfit?

I have variables x,y,z which form a point cloud when plotted by:

library(plot3D)
plot3d(x,y,z)

I did a locfit on them

myfit = locfit(y~lp(x,z),maxk=200)

I understand that this will give me a curve that goes through the most dense region of space.

How do I plot this curve in plot3d / RGL?

Use surface3d . x and y are vectors for the margins and z is a matrix:

require(locfit)
fit <- locfit(NOx~lp(E,C,nn=0.5,scale=0), data=ethanol)
plot(locfit)  # there is an ordinary contour plot method for locfit objects.

require(rgl)
open3d()
surface3d( x=seq(0.5, 1.3, by=0.1), y=seq(7.5,18,by=.5) ,
           z= matrix(  predict(fit, newdata= 
                           expand.grid(E=seq(0.5, 1.3, by=0.1), 
                                       C=seq(7.5,18,by=.5) ) ) ),
                      ,nrow= length(seq(0.5, 1.3, by=0.1)) ,
                       ncol= length(seq(7.5,18,by=.5) ) ,
           xlim=c(.5, 1.3) )
 # grab and spin

I actually find the contour plots more informative, but the 3d plots can be useful, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM