1

I want to plot as below. I tried to search several packages and plot functions but I couldn't find a solution.

My data has four columns.

ID  F  R  M
 1  2  3  4
 2  4  6  7
...

I want to see the relationship between M and R with respect to each F value (1, 2, 3, ...). So, I'd like F along the x-axis, R along the y-axis, and M as the z-axis as in the below graph.

Thanks.

enter image description here

jbaums
  • 27,115
  • 5
  • 79
  • 119
Boram Lim
  • 313
  • 3
  • 15
  • 2
    What you have tried apart from searching? what is your use case or sample dataset? Provide some more information... – vrajs5 Jun 16 '14 at 05:29
  • I edited and explained more. Thanks! – Boram Lim Jun 16 '14 at 05:58
  • 1
    That seems a bit weak on the volume of data for a sample dataset. It's not going to make a very interesting graph. I've see somewhat similar images in the _Lattice_ text and I would not think it would be particularly difficult in pkg-`rgl` – IRTFM Jun 16 '14 at 06:02
  • 4
    I'd skip the 3D, and use color for the third dimension. Already in the example you show, part of the graphs in the back are obscured by graphs before it. – Paul Hiemstra Jun 16 '14 at 06:09
  • 1
    Have a look at the problem with occlusion that Stephen Few (respected graphing expert) says about 3-D graphics on page 17: http://mkt.tableausoftware.com/downloads/TCC08-Keynote-Stephen-Few.pdf @jbaums gives a correct answer to the wrong question (+1 to him). – Tyler Rinker Jun 16 '14 at 14:34

1 Answers1

4

You can do this kind of thing with lattice cloud plots, using panel.3dpolygon from latticeExtra.

library(latticeExtra)

# generating random data
d <- data.frame(x=rep(1:40, 7), y=rep(1:7, each=40), 
                z=c(sapply(1:7, function(x) runif(40, 10*x, 10*x+20))))

# define the panel function
f <- function(x, y, z, groups, subscripts, ...) {
  colorz <- c('#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', 
              '#fdb462', '#b3de69')
  sapply(sort(unique(groups), decreasing=TRUE), function(i) {
    zz <- z[subscripts][groups==i]
    yy <- y[subscripts][groups==i]
    xx <- x[subscripts][groups==i]    
    panel.3dpolygon(c(xx, rev(xx)), c(yy, yy), 
                    c(zz, rep(-0.5, length(zz))), 
                    col=colorz[i], ...)
  })

}

# plot
cloud(z~x+y, d, groups=y, panel.3d.cloud=f, scales=list(arrows=FALSE))

I'm sure I don't need to loop over groups in the panel function, but I always forget the correct incantation for subscripts and groups to work as intended.

As others have mentioned in comments, this type of plot might look snazzy, but can obscure data.

enter image description here

jbaums
  • 27,115
  • 5
  • 79
  • 119