R plot gam 3D surface to show also actual response values The Next CEO of Stack OverflowRough 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
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Limits on contract work without pre-agreed price/contract (UK)
What benefits would be gained by using human laborers instead of drones in deep sea mining?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
sp_blitzCache results Memory grants
Should I tutor a student who I know has cheated on their homework?
What exact does MIB represent in SNMP? How is it different from OID?
What is the result of assigning to std::vector<T>::begin()?
What can we do to stop prior company from asking us questions?
Does it take more energy to get to Venus or to Mars?
What flight has the highest ratio of time difference to flight time?
How fast would a person need to move to trick the eye?
Interfacing a button to MCU (and PC) with 50m long cable
Is HostGator storing my password in plaintext?
Written every which way
Return the Closest Prime Number
How to start emacs in "nothing" mode (`fundamental-mode`)
Is it possible to search for a directory/file combination?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Why do professional authors make "consistency" mistakes? And how to avoid them?
What's the best way to handle refactoring a big file?
Why does standard notation not preserve intervals (visually)
Sending manuscript to multiple publishers
Why does the UK parliament need a vote on the political declaration?
R plot gam 3D surface to show also actual response values
The Next CEO of Stack OverflowRough 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
10.1k11241
10.1k11241
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
Mar 15 at 20:35
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
Mar 15 at 20:35
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
Mar 15 at 20:35
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
10.1k11241
10.1k11241
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
Mar 15 at 20:35
add a comment |
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
Mar 15 at 20:35
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
Mar 15 at 20:35
Absolutely fantastic answer. You made my day. Thank you so much
– Angelo
Mar 15 at 20:35
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