I want to make a 3d plot out of a number of 5 filled.contour
plots by stacking them vertically. It is possible with other software, but I need to use R
. I suppose more exactly this is a 4d plot
The plots should have the same colour scale and a legend bar down the side as you get with the code below
A complex example of the kind of plot I want is provided here
http://www.originlab.com/doc%5Cen/Tutorial/images/Stacked_3D_Surface_Plots/Stacked_3D_Surface.png
So far my code reads as follows:
varx=seq(-250, 250, 25)
vary=seq(-250, 250, 25)
# Import data from csv file
var1=read.csv("~/100.csv", header=F)
var2=read.csv("~/200.csv", header=F)
var3=read.csv("~/300.csv", header=F)
var4=read.csv("~/400.csv", header=F)
var5=read.csv("~/500.csv", header=F)
# Plot filled contour for z1
filled.contour(varx, vary, varz1, nlevels=25, color.palette=heat.colors, xlab="Arbitrary distance", ylab="Arbitrary distance", las=T, key.title=title(main="Intensity"), main="Intensity \nas a function of distance")
I know I can plot my variable varz1
in 3D, but essentially this is no different as the 3rd and colour dimensions are the same.
library("plot3D")
persp3D(x=varx, y=vary, z=varz1, clab = "Energy \nIntensity", bty="b2", xlab="Arbitrary X distance", ylab="Arbitrary Y distance", zlab="Z distance (mm)", theta=35, phi=20, ticktype = "detailed", main="Energy intensity \nas a function of distance")
Anyone have any thoughts?
TANGENT: I'm relatively new to R and haven't figured out how to iterate the filled.contour
command for the 5 variables that I am importing. I'm sure there's a way though!
EDIT: Example code
x1=seq(2, 10, 2)
y1=seq(2, 10, 2)
z1=matrix(c(0,1,2,1,0,1,2,3,2,1,2,3,4,3,2,1,2,3,2,1,0,1,2,1,0), nrow=5, byrow=T)
z2=z1^2/3
z3=z1^3/10
library(rgl)
open3d()
bg3d("white")
elv=0
offs=2*elv+1
nbcol=25
color=rev(rainbow(nbcol, start = 0/6, end = 4/6))
zcol=cut(z3, nbcol)
persp3d(x=x1, y=y1, z=elv*z1+0*offs, col=color[zcol], add=T, axes=F, alpha=0.7,theta=50, phi=25, expand=1);
persp3d(x=x1, y=y1, z=elv*z2+10*offs, col=color[zcol], add=T, axes=T, alpha=0.7);
persp3d(x=x1, y=y1, z=elv*z3+20*offs, col=color[zcol], add=T, axes=F, alpha=0.7)
You can see that the colour contours on each level of the plot are the same when they shouldn't be. I can't figure out how to change this.
Apologies for the delay in coming back to this. Appreciate your inputs