Discussion:
[R] Perspective Plotting - 3D Plotting in R
Thanh Tran
2018-11-26 12:13:03 UTC
Permalink
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



Ps: I also added a CSV file for practicing R.
______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
Thanh Tran
2018-11-26 12:38:27 UTC
Permalink
Hi Farzaneh
If someones answer your question, they will send to your email that you
used in the system.
Best regards,
Nhat Tran.

Vào Th 2, 26 thg 11, 2018 vào lúc 21:20 Ahmadzadeh Siahrood Farzaneh <
Hi Tran ,
It is not relevant to your answer but I want to ask you where do you look
for the answer ? I have posted a question but Don’t know where goes the
relevant answers. I am new for this system if you could help me I would
appreciate.
Best ,
Farzaneh
-----Original Message-----
Sent: den 26 november 2018 13:13
Subject: [R] Perspective Plotting - 3D Plotting in R
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:Tem
p+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 =
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
Ps: I also added a CSV file for practicing R.
______________________________________________
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.
[[alternative HTML version deleted]]

______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
Sarah Goslee
2018-11-26 14:22:02 UTC
Permalink
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
Post by Thanh Tran
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,
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

______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
Duncan Murdoch
2018-11-26 15:17:43 UTC
Permalink
Post by Thanh Tran
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)
For two factors, you could use this code:

pred <- function(AC, AV, Temp, T) predict(mod, newdata = data.frame(AC,
AV, Temp, T))

library(rgl)
persp3d(pred, xlim = c(-1, 1), # The range of values for AC
ylim = c(-1, 1), # The range for AV
xlab = "AC", ylab = "AV", zlab = "KIC",
colour = rainbow, # or a fixed colour, or another fn
otherargs = list(Temp = 0, T = 0))

The otherargs list should contain the values of the two factors to your
model that you are holding fixed while plotting the two that are not fixed.

This Stackoverflow answer
https://stackoverflow.com/questions/53349811/how-to-draw-a-response-surface-plot-for-three-factorial-design/53350259#53350259
describes a way to plot the response to 3 factors at once.

Duncan Murdoch
Post by Thanh Tran
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,
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
Ps: I also added a CSV file for practicing R.
______________________________________________
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-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
Thanh Tran
2018-11-27 05:24:33 UTC
Permalink
Hi Sarah Goslee and Duncan Murdoch
Thank you so much for your answers. Now I can plot the surface needed.
Best regards,
Nhat Tran.

Vào Th 3, 27 thg 11, 2018 vào lúc 00:17 Duncan Murdoch <
Post by Thanh Tran
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,
Post by Thanh Tran
+ data = data)
pred <- function(AC, AV, Temp, T) predict(mod, newdata = data.frame(AC,
AV, Temp, T))
library(rgl)
persp3d(pred, xlim = c(-1, 1), # The range of values for AC
ylim = c(-1, 1), # The range for AV
xlab = "AC", ylab = "AV", zlab = "KIC",
colour = rainbow, # or a fixed colour, or another fn
otherargs = list(Temp = 0, T = 0))
The otherargs list should contain the values of the two factors to your
model that you are holding fixed while plotting the two that are not fixed.
This Stackoverflow answer
https://stackoverflow.com/questions/53349811/how-to-draw-a-response-surface-plot-for-three-factorial-design/53350259#53350259
describes a way to plot the response to 3 factors at once.
Duncan Murdoch
Post by Thanh Tran
I want to have a response surface of KIC with two factors, i.e., AC and
AV
Post by Thanh Tran
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,
Post by Thanh Tran
+ data = data)
Error in persp(AC, AV, KIC ~ AC + I(AC^2) + AV + I(AV^2) + AC:AV,
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
Ps: I also added a CSV file for practicing R.
______________________________________________
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
Post by Thanh Tran
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]

______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
Continue reading on narkive:
Loading...