[R] 3D surface plot with wireframe or persp?

Jin realstone at hotmail.com
Tue Apr 20 17:35:55 CEST 2010


Hello Dear,

I have a function, like z=f(x,y), and try a surface plot with this function.
But, on the reference of "wireframe" requires data option, so I generated x
and y, and computed z with them. But, still I have a problem to draw a
surface plot. The code  and errors are 

##################################################
mle_beta0=64.43707;
mle_beta1=-24365.16;

# generating for the requirement of "wireframe"
data_for_c = runif(1000,30,85);                     # range is (30,50)
data_for_s = sort(1/(273+data_for_c)); 
data_for_time = sort(runif(1000,0,100000))     # range is (0,100000)
data_for_R = exp((-exp(mle_beta0+mle_beta1*data_for_s))*data_for_time)
data_all = cbind(data_for_s,data_for_time,data_for_R)

# function: plot_R_i_3d = f(data_for_time,data_for_s)
	plot_R_i_3d = function(data_for_time,data_for_s)
	{
		
		R_i = exp((-exp(mle_beta0+mle_beta1*data_for_s))*data_for_time);
		return(R_i)
	}

# tried 1) persp or 2) wireframe

persp(data_for_time,data_for_s,plot_R_i_3d)

==> Error in min(x, na.rm = na.rm) : invalid 'type' (list) of argument

wireframe(formula=data_for_R ~ data_for_s*data_for_time,data=data_all)

==> Error in nrow(x) : 
       element 1 is empty;
       the part of the args list of 'dim' being evaluated was:
       (x)
###################################################

I have two questions:

1) which one is better to plot in this case - "persp" and "wireframe", Is
there another suggestion?
2) Is it possible to plot with only a function?
3) If not, what is wrong in the code above?

Many thank you in advance,

Jin


-- 
View this message in context: http://n4.nabble.com/3D-surface-plot-with-wireframe-or-persp-tp2017559p2017559.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list