[R] Smoothed 3D plots

Mark Difford mark_difford at yahoo.co.uk
Wed Nov 26 21:19:27 CET 2008


Hi Jorge,

>> In general terms, I would like to plot a smoothed surface with h4 and h11
>> in
>> the x and y axis, respectively, and y in the z axis. I think that a 
>> smoothing procedure should work but I don't know how to get that work in
>> R.

There are quite a few options. If I were you I would have a look at package
locfit:

plot(locfit(y ~ lp(h4, h11), data=res), type="persp", theta=-50, phi=25,
tick="detailed")

See, amongst other options, ?locfit.raw

Regards, Mark.

PS: Don't worry about the warning messages. They refer to switches that
should be set for panel functions.


Jorge Ivan Velez wrote:
> 
> DeaR list,
> 
> I'm trying to represent some information via 3D plots. My data and session
> info are at the end of this message. So far, I have tried scatterplot3d
> (scatterplot3d),
> persp3d (rgl), persp (graphics) and scatter3d (Rmcdr) but any of them gave
> me what I'd like to have as final result (please see [1] for a similar 3D
> plot changing
> PF by ypred, pdn by h4 and pup by h11).
> 
> In general terms, I would like to plot a smoothed surface with h4 and h11
> in
> the x and y axis, respectively, and y in the z axis. I think that a
> smoothing procedure should
> work but I don't know how to get that work in R.
> 
> I would really appreciate any help you can provide me.
> 
> Thanks in advance,
> 
> Jorge Velez
> 
> [1] http://www.meyersanalytics.com/pfpuppdn.gif
> 
> 
> # -------
> # Data
> # -------
> res=structure(list(ypred = c(0.718230085350727, 0.654361814214854,
> 0.644756374003864, 0.652006785905442, 0.695903817103918,
> 0.812977870063322,
> 0.639339808892218, 0.701034703527025, 0.740110233651808,
> 0.664942946000872,
> 0.866847509624424, 0.652502006511821, 0.650617983864292,
> 0.713152860580267,
> 0.717738908917513, 0.738697216666161, 0.666120460155577,
> 0.652242288736383,
> 0.596880009623886, 0.671197684926038, 0.45, 0.820174620312253,
> 0.665066954282449, 0.735164674202043, 0.696027875479989,
> 0.646119215131913,
> 0.644235192484384, 0.663550099786557), h4 = c(1, 0, 1, 0, 1,
> 1, 1, 0, 0, 0, 1, 2, 2, 1, 0, 0, 0, 0, 2, 0, 2, 1, 1, 0, 0, 0,
> 0, 1), h11 = c(0, 0, 1, 0, 1, 2, 1, 0, 1, 2, 2, 1, 1, 0, 2, 1,
> 2, 0, 1, 2, 2, 2, 0, 1, 1, 0, 0, 0)), .Names = c("y", "h4",
> "h11"), class = "data.frame", row.names = c(NA, -28L))
> 
> 
> # ------------
> # Some plots
> # ------------
> 
> # Option 1
> require(Rcmdr)
> with(res,
> scatter3d(h4,ypred,h11, xlab='Chr4',zlab='Chr11',
> ylab='Ratio',fit=c("linear","quadratic"))
> )
> 
> # Option 2
> require(scatterplot3d)
> with(res,
> scatterplot3d(h4,ypred,h11, xlab='Chr4',zlab='Chr11',ylab='Ratio')
> )
> 
> 
> # -------------
> # Session info
> # -------------
> R version 2.8.0 Patched (2008-11-08 r46864)
> i386-pc-mingw32
> 
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
> 
> attached base packages:
> [1] tcltk     stats     graphics  grDevices utils     datasets  methods
> base
> 
> other attached packages:
> [1] rgl_0.81             mgcv_1.4-1           Rcmdr_1.4-4         
> car_1.2-9
> 
> [5] scatterplot3d_0.3-27 lattice_0.17-15
> 
> loaded via a namespace (and not attached):
> [1] grid_2.8.0
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/Smoothed-3D-plots-tp20706730p20708262.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list