Camarda, Carlo Giovanni wrote:> Dear R-users,
> I'd like to plot a three-dimensional surface and at the meantime
I'm using
> an array. I would like to have the values of my first matrix in the heights
> of the plot and the colors of the single facet taking into account the
> second matrix.
> I hope that the next code will help all of you to understand better my
> issue,
Have you read ?persp carefully? Have you looked at the examples in
demo(persp)? Where is the problem?
> Thanks in advance, Giancarlo
> ############################
> ## creating my array
> m1 <- runif(30,min=1, max=10)
> m2 <- c(rep(0,12), rep(1,5), rep(0,3), rep(1,30-12-5-3))
> mm <- array(c(m1,m2), dim=c(6,5,2))
>
> ## colors
> colo <- c("red", "blue")
>
> ## axis
> x <- 1:6
> y <- 1:5
> z <- mm[,,1]
> z1 <- mm[,,2]
>
> ## surface with heights and colors
> ## related to the first matrix (no good)
> persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = colo,
> ltheta = 120, ticktype = "detailed",
> xlab = "X", ylab = "Y", zlab =
"values" )
Use something like col = colo[mm[-1,-1,2]+1] instead of col=colo. Note
that the color matrix must be (m-1)x(n-1) if z is m x n !!!
Uwe Ligges
> ## surface with heights and colors
> ## related to the second matrix (no good as well)
> persp(x, y, z1, theta = 30, phi = 30, expand = 0.5, col = colo,
> ltheta = 120, ticktype = "detailed",
> xlab = "X", ylab = "Y", zlab =
"values" )
> ############################
>
>
>
> +++++
> This mail has been sent through the MPI for Demographic Rese...{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html