R plot gam 3D surface to show also actual response values2019 Community Moderator ElectionRough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcvggplot2 geom_rug rescales unused axes - how do I stop this?ggplot confidence bands from gam predict$fit and predict$se.fitR: adding droplines to fitted plane in 3D scatterplot in rgl“Cut out” 3D Surface Plot in RSwapping axes for a 2-predictor GAM in rPredict values from multivariate linear modelR: Plotting “Actual vs. Fitted”How to plot raw and predict values for 2x2x2 time-series in R?Is it possible to specify lower bound in response variable during smooth with gam?R - GAM regressions (mgcv) response curves change shape/direction when adding new variables
"of which" is correct here?
Does this sum go infinity?
Employee lack of ownership
If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?
What is "focus distance lower/upper" and how is it different from depth of field?
Is it insecure to send a password in a `curl` command?
Do I need to be arrogant to get ahead?
Examples of transfinite towers
Why Choose Less Effective Armour Types?
Is a party consisting of only a bard, a cleric, and a warlock functional long-term?
Why does overlay work only on the first tcolorbox?
How could a scammer know the apps on my phone / iTunes account?
World War I as a war of liberals against authoritarians?
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
Can I use USB data pins as power source
Adventure Game (text based) in C++
Why is a white electrical wire connected to 2 black wires?
Is there a symmetric-key algorithm which we can use for creating a signature?
Happy pi day, everyone!
Aluminum electrolytic or ceramic capacitors for linear regulator input and output?
Planetary tidal locking causing asymetrical water distribution
Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?
How should I state my peer review experience in the CV?
Print a physical multiplication table
R plot gam 3D surface to show also actual response values
2019 Community Moderator ElectionRough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcvggplot2 geom_rug rescales unused axes - how do I stop this?ggplot confidence bands from gam predict$fit and predict$se.fitR: adding droplines to fitted plane in 3D scatterplot in rgl“Cut out” 3D Surface Plot in RSwapping axes for a 2-predictor GAM in rPredict values from multivariate linear modelR: Plotting “Actual vs. Fitted”How to plot raw and predict values for 2x2x2 time-series in R?Is it possible to specify lower bound in response variable during smooth with gam?R - GAM regressions (mgcv) response curves change shape/direction when adding new variables
I'm quite an R newbie and facing the following challange.
I'll share my code here but applied to a different dataframe since I cannot share the original dataframe.
This is my code:
fit = gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
plot(fit,rug=F,pers=T,theta=45,main="test")
using my company's data, this generates a nice surface with the predicted values on the Z axes.
I would like to add the actual response values as red dots on Z axis so that I could see where predicted values are under/over estimating the actual reponse.
Would you know what parameter I should add to plot in order to do that?
Many thanks
r rgl gam
|
show 2 more comments
I'm quite an R newbie and facing the following challange.
I'll share my code here but applied to a different dataframe since I cannot share the original dataframe.
This is my code:
fit = gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
plot(fit,rug=F,pers=T,theta=45,main="test")
using my company's data, this generates a nice surface with the predicted values on the Z axes.
I would like to add the actual response values as red dots on Z axis so that I could see where predicted values are under/over estimating the actual reponse.
Would you know what parameter I should add to plot in order to do that?
Many thanks
r rgl gam
That's not easy. Theplot
function usespersp
to draw the surface.persp
returns enough information to add points, but theplot
function doesn't save it.
– user2554330
Mar 7 at 16:39
This Q&A contains code to guide you how to do this. You need to callpredict.gam
,perps
,trans3d
,points
andsegments
. Working withplot.gam
is not a good idea because smooth functions are centered, and it would be hard for you to work out the vertical shift correctly.
– 李哲源
Mar 7 at 16:54
@李哲源 which Q&A are you referring to?
– Angelo
Mar 7 at 17:20
@Angelo Oh I did not link it! Sorry, here it is: stackoverflow.com/q/52279218/4891738
– 李哲源
Mar 7 at 17:28
@李哲源: Nice! You should write this up as an answer: I don't think the question is a duplicate of the linked one.
– user2554330
Mar 7 at 17:34
|
show 2 more comments
I'm quite an R newbie and facing the following challange.
I'll share my code here but applied to a different dataframe since I cannot share the original dataframe.
This is my code:
fit = gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
plot(fit,rug=F,pers=T,theta=45,main="test")
using my company's data, this generates a nice surface with the predicted values on the Z axes.
I would like to add the actual response values as red dots on Z axis so that I could see where predicted values are under/over estimating the actual reponse.
Would you know what parameter I should add to plot in order to do that?
Many thanks
r rgl gam
I'm quite an R newbie and facing the following challange.
I'll share my code here but applied to a different dataframe since I cannot share the original dataframe.
This is my code:
fit = gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
plot(fit,rug=F,pers=T,theta=45,main="test")
using my company's data, this generates a nice surface with the predicted values on the Z axes.
I would like to add the actual response values as red dots on Z axis so that I could see where predicted values are under/over estimating the actual reponse.
Would you know what parameter I should add to plot in order to do that?
Many thanks
r rgl gam
r rgl gam
edited Mar 7 at 20:01
user2554330
9,98211241
9,98211241
asked Mar 7 at 15:28
AngeloAngelo
7510
7510
That's not easy. Theplot
function usespersp
to draw the surface.persp
returns enough information to add points, but theplot
function doesn't save it.
– user2554330
Mar 7 at 16:39
This Q&A contains code to guide you how to do this. You need to callpredict.gam
,perps
,trans3d
,points
andsegments
. Working withplot.gam
is not a good idea because smooth functions are centered, and it would be hard for you to work out the vertical shift correctly.
– 李哲源
Mar 7 at 16:54
@李哲源 which Q&A are you referring to?
– Angelo
Mar 7 at 17:20
@Angelo Oh I did not link it! Sorry, here it is: stackoverflow.com/q/52279218/4891738
– 李哲源
Mar 7 at 17:28
@李哲源: Nice! You should write this up as an answer: I don't think the question is a duplicate of the linked one.
– user2554330
Mar 7 at 17:34
|
show 2 more comments
That's not easy. Theplot
function usespersp
to draw the surface.persp
returns enough information to add points, but theplot
function doesn't save it.
– user2554330
Mar 7 at 16:39
This Q&A contains code to guide you how to do this. You need to callpredict.gam
,perps
,trans3d
,points
andsegments
. Working withplot.gam
is not a good idea because smooth functions are centered, and it would be hard for you to work out the vertical shift correctly.
– 李哲源
Mar 7 at 16:54
@李哲源 which Q&A are you referring to?
– Angelo
Mar 7 at 17:20
@Angelo Oh I did not link it! Sorry, here it is: stackoverflow.com/q/52279218/4891738
– 李哲源
Mar 7 at 17:28
@李哲源: Nice! You should write this up as an answer: I don't think the question is a duplicate of the linked one.
– user2554330
Mar 7 at 17:34
That's not easy. The
plot
function uses persp
to draw the surface. persp
returns enough information to add points, but the plot
function doesn't save it.– user2554330
Mar 7 at 16:39
That's not easy. The
plot
function uses persp
to draw the surface. persp
returns enough information to add points, but the plot
function doesn't save it.– user2554330
Mar 7 at 16:39
This Q&A contains code to guide you how to do this. You need to call
predict.gam
, perps
, trans3d
, points
and segments
. Working with plot.gam
is not a good idea because smooth functions are centered, and it would be hard for you to work out the vertical shift correctly.– 李哲源
Mar 7 at 16:54
This Q&A contains code to guide you how to do this. You need to call
predict.gam
, perps
, trans3d
, points
and segments
. Working with plot.gam
is not a good idea because smooth functions are centered, and it would be hard for you to work out the vertical shift correctly.– 李哲源
Mar 7 at 16:54
@李哲源 which Q&A are you referring to?
– Angelo
Mar 7 at 17:20
@李哲源 which Q&A are you referring to?
– Angelo
Mar 7 at 17:20
@Angelo Oh I did not link it! Sorry, here it is: stackoverflow.com/q/52279218/4891738
– 李哲源
Mar 7 at 17:28
@Angelo Oh I did not link it! Sorry, here it is: stackoverflow.com/q/52279218/4891738
– 李哲源
Mar 7 at 17:28
@李哲源: Nice! You should write this up as an answer: I don't think the question is a duplicate of the linked one.
– user2554330
Mar 7 at 17:34
@李哲源: Nice! You should write this up as an answer: I don't think the question is a duplicate of the linked one.
– user2554330
Mar 7 at 17:34
|
show 2 more comments
1 Answer
1
active
oldest
votes
As @李哲源 pointed out in the comments, you shouldn't use plot
here, because it's not flexible enough. Here's a version based on the referenced question Rough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcv.
# First, get the fit
library(mgcv)
fit <- gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
# Now expand it to a grid so that persp will work
steps <- 30
cyl <- with(mtcars, seq(min(cyl), max(cyl), length = steps) )
hp <- with(mtcars, seq(min(hp), max(hp), length = steps) )
newdat <- expand.grid(cyl = cyl, hp = hp)
carb <- matrix(predict(fit, newdat), steps, steps)
# Now plot it
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
# To add the points, you need the same 3d transformation
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
# Add segments to show where the points are in 3d
segments(obs$x, obs$y, pred$x, pred$y)
That produces the following plot:
You might not want to make predictions so far from the observed data. You can put NA
values into carb
to avoid that. This code does that:
exclude <- exclude.too.far(rep(cyl,steps),
rep(hp, rep(steps, steps)),
mtcars$cyl,
mtcars$hp, 0.15) # 0.15 chosen by trial and error
carb[exclude] <- NA
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
segments(obs$x, obs$y, pred$x, pred$y)
That produces this plot:
Finally, you might want to use the rgl
package to get a dynamic graph instead. After the same manipulations as above, use this code to do the plotting:
library(rgl)
persp3d(cyl, hp, carb, col="yellow", polygon_offset = 1)
surface3d(cyl, hp, carb, front = "lines", back = "lines")
with(mtcars, points3d(cyl, hp, carb, col = "red"))
with(mtcars, segments3d(rep(cyl, each = 2),
rep(hp, each = 2),
as.numeric(rbind(fitted(fit),
carb))))
Here's one possible view:
You can use the mouse to rotate this one if you want to see it from a different angle. One other advantage is that points that should be hidden by the surface really are hidden; in persp
, they'll plot on top even if they should be behind it.
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
yesterday
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047365%2fr-plot-gam-3d-surface-to-show-also-actual-response-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As @李哲源 pointed out in the comments, you shouldn't use plot
here, because it's not flexible enough. Here's a version based on the referenced question Rough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcv.
# First, get the fit
library(mgcv)
fit <- gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
# Now expand it to a grid so that persp will work
steps <- 30
cyl <- with(mtcars, seq(min(cyl), max(cyl), length = steps) )
hp <- with(mtcars, seq(min(hp), max(hp), length = steps) )
newdat <- expand.grid(cyl = cyl, hp = hp)
carb <- matrix(predict(fit, newdat), steps, steps)
# Now plot it
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
# To add the points, you need the same 3d transformation
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
# Add segments to show where the points are in 3d
segments(obs$x, obs$y, pred$x, pred$y)
That produces the following plot:
You might not want to make predictions so far from the observed data. You can put NA
values into carb
to avoid that. This code does that:
exclude <- exclude.too.far(rep(cyl,steps),
rep(hp, rep(steps, steps)),
mtcars$cyl,
mtcars$hp, 0.15) # 0.15 chosen by trial and error
carb[exclude] <- NA
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
segments(obs$x, obs$y, pred$x, pred$y)
That produces this plot:
Finally, you might want to use the rgl
package to get a dynamic graph instead. After the same manipulations as above, use this code to do the plotting:
library(rgl)
persp3d(cyl, hp, carb, col="yellow", polygon_offset = 1)
surface3d(cyl, hp, carb, front = "lines", back = "lines")
with(mtcars, points3d(cyl, hp, carb, col = "red"))
with(mtcars, segments3d(rep(cyl, each = 2),
rep(hp, each = 2),
as.numeric(rbind(fitted(fit),
carb))))
Here's one possible view:
You can use the mouse to rotate this one if you want to see it from a different angle. One other advantage is that points that should be hidden by the surface really are hidden; in persp
, they'll plot on top even if they should be behind it.
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
yesterday
add a comment |
As @李哲源 pointed out in the comments, you shouldn't use plot
here, because it's not flexible enough. Here's a version based on the referenced question Rough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcv.
# First, get the fit
library(mgcv)
fit <- gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
# Now expand it to a grid so that persp will work
steps <- 30
cyl <- with(mtcars, seq(min(cyl), max(cyl), length = steps) )
hp <- with(mtcars, seq(min(hp), max(hp), length = steps) )
newdat <- expand.grid(cyl = cyl, hp = hp)
carb <- matrix(predict(fit, newdat), steps, steps)
# Now plot it
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
# To add the points, you need the same 3d transformation
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
# Add segments to show where the points are in 3d
segments(obs$x, obs$y, pred$x, pred$y)
That produces the following plot:
You might not want to make predictions so far from the observed data. You can put NA
values into carb
to avoid that. This code does that:
exclude <- exclude.too.far(rep(cyl,steps),
rep(hp, rep(steps, steps)),
mtcars$cyl,
mtcars$hp, 0.15) # 0.15 chosen by trial and error
carb[exclude] <- NA
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
segments(obs$x, obs$y, pred$x, pred$y)
That produces this plot:
Finally, you might want to use the rgl
package to get a dynamic graph instead. After the same manipulations as above, use this code to do the plotting:
library(rgl)
persp3d(cyl, hp, carb, col="yellow", polygon_offset = 1)
surface3d(cyl, hp, carb, front = "lines", back = "lines")
with(mtcars, points3d(cyl, hp, carb, col = "red"))
with(mtcars, segments3d(rep(cyl, each = 2),
rep(hp, each = 2),
as.numeric(rbind(fitted(fit),
carb))))
Here's one possible view:
You can use the mouse to rotate this one if you want to see it from a different angle. One other advantage is that points that should be hidden by the surface really are hidden; in persp
, they'll plot on top even if they should be behind it.
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
yesterday
add a comment |
As @李哲源 pointed out in the comments, you shouldn't use plot
here, because it's not flexible enough. Here's a version based on the referenced question Rough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcv.
# First, get the fit
library(mgcv)
fit <- gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
# Now expand it to a grid so that persp will work
steps <- 30
cyl <- with(mtcars, seq(min(cyl), max(cyl), length = steps) )
hp <- with(mtcars, seq(min(hp), max(hp), length = steps) )
newdat <- expand.grid(cyl = cyl, hp = hp)
carb <- matrix(predict(fit, newdat), steps, steps)
# Now plot it
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
# To add the points, you need the same 3d transformation
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
# Add segments to show where the points are in 3d
segments(obs$x, obs$y, pred$x, pred$y)
That produces the following plot:
You might not want to make predictions so far from the observed data. You can put NA
values into carb
to avoid that. This code does that:
exclude <- exclude.too.far(rep(cyl,steps),
rep(hp, rep(steps, steps)),
mtcars$cyl,
mtcars$hp, 0.15) # 0.15 chosen by trial and error
carb[exclude] <- NA
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
segments(obs$x, obs$y, pred$x, pred$y)
That produces this plot:
Finally, you might want to use the rgl
package to get a dynamic graph instead. After the same manipulations as above, use this code to do the plotting:
library(rgl)
persp3d(cyl, hp, carb, col="yellow", polygon_offset = 1)
surface3d(cyl, hp, carb, front = "lines", back = "lines")
with(mtcars, points3d(cyl, hp, carb, col = "red"))
with(mtcars, segments3d(rep(cyl, each = 2),
rep(hp, each = 2),
as.numeric(rbind(fitted(fit),
carb))))
Here's one possible view:
You can use the mouse to rotate this one if you want to see it from a different angle. One other advantage is that points that should be hidden by the surface really are hidden; in persp
, they'll plot on top even if they should be behind it.
As @李哲源 pointed out in the comments, you shouldn't use plot
here, because it's not flexible enough. Here's a version based on the referenced question Rough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcv.
# First, get the fit
library(mgcv)
fit <- gam( carb ~ te(cyl, hp, k=c(3,4)), data = mtcars)
# Now expand it to a grid so that persp will work
steps <- 30
cyl <- with(mtcars, seq(min(cyl), max(cyl), length = steps) )
hp <- with(mtcars, seq(min(hp), max(hp), length = steps) )
newdat <- expand.grid(cyl = cyl, hp = hp)
carb <- matrix(predict(fit, newdat), steps, steps)
# Now plot it
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
# To add the points, you need the same 3d transformation
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
# Add segments to show where the points are in 3d
segments(obs$x, obs$y, pred$x, pred$y)
That produces the following plot:
You might not want to make predictions so far from the observed data. You can put NA
values into carb
to avoid that. This code does that:
exclude <- exclude.too.far(rep(cyl,steps),
rep(hp, rep(steps, steps)),
mtcars$cyl,
mtcars$hp, 0.15) # 0.15 chosen by trial and error
carb[exclude] <- NA
p <- persp(cyl, hp, carb, theta = 45, col = "yellow")
obs <- with(mtcars, trans3d(cyl, hp, carb, p))
pred <- with(mtcars, trans3d(cyl, hp, fitted(fit), p))
points(obs, col = "red", pch = 16)
segments(obs$x, obs$y, pred$x, pred$y)
That produces this plot:
Finally, you might want to use the rgl
package to get a dynamic graph instead. After the same manipulations as above, use this code to do the plotting:
library(rgl)
persp3d(cyl, hp, carb, col="yellow", polygon_offset = 1)
surface3d(cyl, hp, carb, front = "lines", back = "lines")
with(mtcars, points3d(cyl, hp, carb, col = "red"))
with(mtcars, segments3d(rep(cyl, each = 2),
rep(hp, each = 2),
as.numeric(rbind(fitted(fit),
carb))))
Here's one possible view:
You can use the mouse to rotate this one if you want to see it from a different angle. One other advantage is that points that should be hidden by the surface really are hidden; in persp
, they'll plot on top even if they should be behind it.
answered Mar 7 at 18:34
user2554330user2554330
9,98211241
9,98211241
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
yesterday
add a comment |
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
yesterday
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
yesterday
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
yesterday
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047365%2fr-plot-gam-3d-surface-to-show-also-actual-response-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
That's not easy. The
plot
function usespersp
to draw the surface.persp
returns enough information to add points, but theplot
function doesn't save it.– user2554330
Mar 7 at 16:39
This Q&A contains code to guide you how to do this. You need to call
predict.gam
,perps
,trans3d
,points
andsegments
. Working withplot.gam
is not a good idea because smooth functions are centered, and it would be hard for you to work out the vertical shift correctly.– 李哲源
Mar 7 at 16:54
@李哲源 which Q&A are you referring to?
– Angelo
Mar 7 at 17:20
@Angelo Oh I did not link it! Sorry, here it is: stackoverflow.com/q/52279218/4891738
– 李哲源
Mar 7 at 17:28
@李哲源: Nice! You should write this up as an answer: I don't think the question is a duplicate of the linked one.
– user2554330
Mar 7 at 17:34