Hello: I would like to be able to do a 3D scatter plot from 3 variables, 2 independent and 1 dependent. The closest R function I could find for this is "cloud". However cloud uses, as input, a matrix where the value of each matrix element is the dependent variable value at that matrix coordinate. My problem is that the independent variable values are floating point and can be of any value. Consequently some of the matrix bins may not have a value assigned. An example of the sort of data I may have is as follows Independent 1 Independent 2 Dependent 0.145674 0.526482534 1.676986 0.325634 0.326385237 2.384384 0.235267 0.352653288 0.356483 Is there any way to do a 3D scatter plot with this sort of data? Thanks very much in advance, Peter Lauren. [[alternative HTML version deleted]]
On 6/17/05, Lauren, Peter <Peter.Lauren at essexcorp.com> wrote:> Hello: > > > > I would like to be able to do a 3D scatter plot from 3 variables, 2 > independent and 1 dependent. The closest R function I could find for > this is "cloud". However cloud uses, as input, a matrix where the value > of each matrix element is the dependent variable value at that matrix > coordinate.What makes you think that?> My problem is that the independent variable values are > floating point and can be of any value. Consequently some of the matrix > bins may not have a value assigned. An example of the sort of data I > may have is as follows > > > > Independent 1 Independent 2 Dependent > > 0.145674 0.526482534 1.676986 > > 0.325634 0.326385237 2.384384 > > 0.235267 0.352653288 0.356483 > > > > Is there any way to do a 3D scatter plot with this sort of data?The following should work fine: df <- data.frame(x = c(0.145674, 0.325634, 0.235267), y = c(0.526482534, 0.326385237, 0.352653288), z = c(1.676986, 2.384384, 0.356483)) cloud(z ~ x * y, df) Deepayan
Hi, I ran into a dilemma trying to plot the following data in a 3d scatter fashion. My data are not always increasing as persp() expects. For now I use scatterplot3d to get points in a 3d scatter plot. I wonder if I have any way to plot the surfaces. Thanks! Eric ####sample data -0.50 0.40 1.281 -0.50 0.45 1.795 -0.50 0.50 1.766 -0.40 0.35 1.595 -0.40 0.40 1.388 -0.40 0.45 2.344 -0.40 0.50 2.179 -0.30 0.35 1.792 -0.30 0.40 2.349 -0.30 0.45 1.682 -0.30 0.50 1.493 -0.20 0.35 1.836 -0.20 0.40 2.186 -0.20 0.45 1.863 -0.20 0.50 1.775 -0.10 0.25 2.991 -0.10 0.30 2.426 -0.10 0.35 1.954 -0.10 0.40 1.136 -0.10 0.45 1.438 -0.10 0.50 1.429 -0.05 0.30 2.163 -0.05 0.35 1.953 -0.05 0.40 1.672 -0.05 0.45 1.688 -0.05 0.50 1.963
Eric Hu wrote:> Hi, I ran into a dilemma trying to plot the following data in a 3d > scatter fashion. My data are not always increasing as persp() expects. > For now I use scatterplot3d to get points in a 3d scatter plot. I > wonder if I have any way to plot the surfaces. Thanks! > > Eric > > > ####sample data > > -0.50 0.40 1.281 > -0.50 0.45 1.795 > -0.50 0.50 1.766 > -0.40 0.35 1.595 > -0.40 0.40 1.388 > -0.40 0.45 2.344 > -0.40 0.50 2.179 > -0.30 0.35 1.792 > -0.30 0.40 2.349 > -0.30 0.45 1.682 > -0.30 0.50 1.493 > -0.20 0.35 1.836 > -0.20 0.40 2.186 > -0.20 0.45 1.863 > -0.20 0.50 1.775 > -0.10 0.25 2.991 > -0.10 0.30 2.426 > -0.10 0.35 1.954 > -0.10 0.40 1.136 > -0.10 0.45 1.438 > -0.10 0.50 1.429 > -0.05 0.30 2.163 > -0.05 0.35 1.953 > -0.05 0.40 1.672 > -0.05 0.45 1.688 > -0.05 0.50 1.963 >?wireframe in the lattice package may help. --sundar
Hey Sundar I guess it works indeed. I had made a stupid mistake. Thanks. Eric On Jul 15, 2005, at 11:24 AM, Sundar Dorai-Raj wrote:> Hi, Eric, > > I plotted a surface using the first two columns as x and y and the > third column for z: > > library(lattice) > v <- read.table("clipboard") > names(v) <- c("x", "y", "z") > wireframe(z ~ x * y, data = v) > > The result is attached. Am I missing something? > > Thanks, > > --sundar > > Eric Hu wrote: >> Ok, I don't think x and y lay on a rectangle which explains why >> wireframe does not work. BTW, I am really new to R and maybe you can >> plot those data to prove that I am wrong. Thanks. >> Eric >> On Jul 15, 2005, at 10:56 AM, Sundar Dorai-Raj wrote: >>> >>> >>> Eric Hu wrote: >>> >>>> Hi, I ran into a dilemma trying to plot the following data in a 3d >>>> scatter fashion. My data are not always increasing as persp() >>>> expects. For now I use scatterplot3d to get points in a 3d scatter >>>> plot. I wonder if I have any way to plot the surfaces. Thanks! >>>> Eric >>>> ####sample data >>>> -0.50 0.40 1.281 >>>> -0.50 0.45 1.795 >>>> -0.50 0.50 1.766 >>>> -0.40 0.35 1.595 >>>> -0.40 0.40 1.388 >>>> -0.40 0.45 2.344 >>>> -0.40 0.50 2.179 >>>> -0.30 0.35 1.792 >>>> -0.30 0.40 2.349 >>>> -0.30 0.45 1.682 >>>> -0.30 0.50 1.493 >>>> -0.20 0.35 1.836 >>>> -0.20 0.40 2.186 >>>> -0.20 0.45 1.863 >>>> -0.20 0.50 1.775 >>>> -0.10 0.25 2.991 >>>> -0.10 0.30 2.426 >>>> -0.10 0.35 1.954 >>>> -0.10 0.40 1.136 >>>> -0.10 0.45 1.438 >>>> -0.10 0.50 1.429 >>>> -0.05 0.30 2.163 >>>> -0.05 0.35 1.953 >>>> -0.05 0.40 1.672 >>>> -0.05 0.45 1.688 >>>> -0.05 0.50 1.963 >>> >>> >>> >>> ?wireframe in the lattice package may help. >>> >>> --sundar >>> >>> >>> > <wf.png>