[R] Perspective Plotting - 3D Plotting in R

Sarah Goslee @@r@h@go@lee @ending from gm@il@com
Mon Nov 26 15:22:02 CET 2018


Hi,

Checking the help for persp shows that it doesn't take a data
argument. Assuming the rest of your code is correct (since no
reproducible example, it's impossible to check), you could do

with(data, persp(AC,AV,KIC~ AC + I(AC^2) + AV + I(AV^2) + AC:AV,image
= TRUE,theta=30))

But. I highly doubt that anything you're doing in that line of code is
correct. There's no image argument either, and x and y must be the
locations of grid lines in ascending order, not just all of your data.
z must be the value to be plotted at those locations.

So what you probably need to do, is figure out what grid points you
want to use, and use predict with your mod object to get the z values
at those points. Then you can plot the corresponding surface. The
first example in ?persp might give you some insight.

Sarah


On Mon, Nov 26, 2018 at 7:15 AM Thanh Tran <masternhattt using gmail.com> wrote:
>
> Dear all,
>
>
>
> I'm trying to plot a surface over the x-y plane. In my data, the response
> is KIC, and four factors are AC, AV, T, and Temp. A typical second-degree
> response modeling is as follows
>
>
> > data<-read.csv("2.csv", header =T)
>
> > mod <- lm(KIC~AC+I(AC^2)+AV+I(AV^2)+T+I(T^2)+Temp+I(Temp^2)+AC:AV+AC:T+AC:Temp+AV:T+AV:Temp+T:Temp,
>
> + data = data)
>
>
>
> I want to have a response surface of KIC with two factors, i.e., AC and AV
> as shown in the attached figure.
>
> When I run the below code, I have a problem which indicates “object 'AC'
> not found” even though I added “data = data”
>
>
>
> > persp(AC,AV,KIC~ AC + I(AC^2) + AV + I(AV^2) + AC:AV,image = TRUE,theta=30,
>
> + data = data)
>
> Error in persp(AC, AV, KIC ~ AC + I(AC^2) + AV + I(AV^2) + AC:AV,
> image = TRUE,  :
>
>   object 'AC' not found
>
>
>
> If anyone has any experience about what would be the reason for error or
> how I can solve it? Is there other simple function to plot the response
> surface?
>
> I really appreciate your support and help.
>
>
>
> Best regards,
>
> Nhat Tran
>



-- 
Sarah Goslee (she/her)
http://www.numberwright.com



More information about the R-help mailing list