1

I am pretty new to plotting 3D graphs in R. I can easily work on scatter plot in 2D.

Here I am showing only Z1 just for the assumption of data. In reality Z2 also exists.

I have a dataset something like:

  X    Y       Z1
 10 8017 5.238290
 13 8273 5.368710
 15 9500 5.908030
 17 6856 6.501010
 19 8453 7.319200
 20 4517 6.258901
 21 7095 5.781290
 24 7738 6.979810
 25 8561 6.563700
 26 7111 6.636700
 29 9596 9.374410

How can I plot A along the x axis, B along the y axis and Z1 along the z axis? How can I form a bar 3d, mesh 3d and patch 3d ?

I did try on surface3d and plot3d but got error in handling data.

Please help on this.

The plot3d command produces a plot which is of no use. and also type is not working inside this command to change the shape (giving a blank plot page).

b <- read.table("dataset", header = T)

plot3d(b$X, b$Y, b$Z, xlab="x", ylab="y", zlab="z", col=rainbow(1000))

enter image description here

Instead of scattered points of Z1 along x and y, I'd like Z1 to be shown as 3D bars.

And surface3d is throwing error like

"Error in rgl.surface(x = c(10L, 13L, 15L, 17L, 19L, 20L, 21L, 24L, 25L,  : 
  y length != x rows * z cols"

My data is already combined into a dataset and I am accessing separate column into the surface3d command but I don't have a clue what else I need to do.

jbaums
  • 27,115
  • 5
  • 79
  • 119
cppiscute
  • 707
  • 2
  • 10
  • 33
  • 2
    Never just say "I got an error". You should tell us what your error is. – jbaums Jun 17 '14 at 23:22
  • 1
    can you show us the code you tried and the error you received? – Ben Bolker Jun 17 '14 at 23:22
  • 2
    also, if you want `Z1` and `Z2` both plotted it would be good to present an example that includes both. Otherwise you're likely to be disappointed (and answerers will be frustrated). – Ben Bolker Jun 17 '14 at 23:23
  • I will post the results in a minute. – cppiscute Jun 17 '14 at 23:26
  • 2
    Check out the `latticeExtra` package. For a single `z` variable it's pretty straightforward to adapt the examples in the docs, e.g., `?panel.3dbars`. For example: `cloud(Z1~X+Y, d, panel.3d.cloud=panel.3dbars, xbase=1, ybase=300, scales=list(arrows=FALSE))` (where `d` is your data.frame). – jbaums Jun 17 '14 at 23:37
  • `surface3d`requires that `x` and `y` are the row and column numbers of your `z` (or that `z` is a matrix representing the surface). See [this post](http://stackoverflow.com/a/4052052/489704) for a way to interpolate your data into regularly-spaced points. – jbaums Jun 17 '14 at 23:53
  • Yeah I am going through, But your previous hint, works well except I need to beautify it a little. But I will go through surface3d also just to check which one produces better plots and flexibility. Thanks – cppiscute Jun 17 '14 at 23:55
  • A lot of Sarkar's Lattice book is available as a [Google Book](http://books.google.com.au/books?id=gXxKFWkE9h0C&printsec=frontcover#v=onepage&q&f=false) - worth checking out. But... representing one of your three dimensions with colour (i.e. multiple series of differently coloured lines) might get your message across more simply. Think about whether you even need a 3d plot. – jbaums Jun 17 '14 at 23:58

0 Answers0