[R] Perspective Plotting - 3D Plotting in R
Duncan Murdoch
murdoch@dunc@n @ending from gm@il@com
Mon Nov 26 16:17:43 CET 2018
On 26/11/2018 7:13 AM, Thanh Tran 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)
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
>
>
>
> 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-help using 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.
>
More information about the R-help
mailing list