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

2010-04-21 Thread Uwe Ligges
You cannot specify a dfunction for z, but need to compute the values in 
the matrix yourself as in:


persp(data_for_time, data_for_s,
outer(data_for_time, data_for_s, plot_R_i_3d))

Uwe Ligges




On 20.04.2010 17:35, Jin wrote:


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,10)) # range is (0,10)
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




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2010-04-20 Thread Jin

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,10)) # range is (0,10)
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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.