Smoothing 3d plot in R

Multi tool use
up vote
1
down vote
favorite
I made 3d plot in rgl.persp3d but I don't know how to smooth that to see trend. Or maybe next solution is to implement wireframe in rgl.persp3d (because I need this plot to be interactive). Please, help.
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
wyk <- matrix(fitted(mod), ncol = 20) #8 i 10 też ok
wireframe(wyk, drape=TRUE, colorkey=TRUE)
#surface persp3d
library(rgl)
library(akima)
z_interpolation <- 200
tabint <- interp(x, y, z)
x.si <- tabint$x
y.si <- tabint$y
z.si <- tabint$z
nbcol <- 200
vertcol <- cut(t, nbcol)
color = rev(rainbow(nbcol, start = 0/6, end = 4/6))
persp3d(x.si, y.si, z.si, col = color[vertcol], smooth=T)
So wireframe is neither smoothed nor interactive
...and rgl.persp3d is interactive but no smoothed. And I can't have both smoothed and interactive.
r rgl wireframe
add a comment |
up vote
1
down vote
favorite
I made 3d plot in rgl.persp3d but I don't know how to smooth that to see trend. Or maybe next solution is to implement wireframe in rgl.persp3d (because I need this plot to be interactive). Please, help.
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
wyk <- matrix(fitted(mod), ncol = 20) #8 i 10 też ok
wireframe(wyk, drape=TRUE, colorkey=TRUE)
#surface persp3d
library(rgl)
library(akima)
z_interpolation <- 200
tabint <- interp(x, y, z)
x.si <- tabint$x
y.si <- tabint$y
z.si <- tabint$z
nbcol <- 200
vertcol <- cut(t, nbcol)
color = rev(rainbow(nbcol, start = 0/6, end = 4/6))
persp3d(x.si, y.si, z.si, col = color[vertcol], smooth=T)
So wireframe is neither smoothed nor interactive
...and rgl.persp3d is interactive but no smoothed. And I can't have both smoothed and interactive.
r rgl wireframe
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I made 3d plot in rgl.persp3d but I don't know how to smooth that to see trend. Or maybe next solution is to implement wireframe in rgl.persp3d (because I need this plot to be interactive). Please, help.
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
wyk <- matrix(fitted(mod), ncol = 20) #8 i 10 też ok
wireframe(wyk, drape=TRUE, colorkey=TRUE)
#surface persp3d
library(rgl)
library(akima)
z_interpolation <- 200
tabint <- interp(x, y, z)
x.si <- tabint$x
y.si <- tabint$y
z.si <- tabint$z
nbcol <- 200
vertcol <- cut(t, nbcol)
color = rev(rainbow(nbcol, start = 0/6, end = 4/6))
persp3d(x.si, y.si, z.si, col = color[vertcol], smooth=T)
So wireframe is neither smoothed nor interactive
...and rgl.persp3d is interactive but no smoothed. And I can't have both smoothed and interactive.
r rgl wireframe
I made 3d plot in rgl.persp3d but I don't know how to smooth that to see trend. Or maybe next solution is to implement wireframe in rgl.persp3d (because I need this plot to be interactive). Please, help.
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
wyk <- matrix(fitted(mod), ncol = 20) #8 i 10 też ok
wireframe(wyk, drape=TRUE, colorkey=TRUE)
#surface persp3d
library(rgl)
library(akima)
z_interpolation <- 200
tabint <- interp(x, y, z)
x.si <- tabint$x
y.si <- tabint$y
z.si <- tabint$z
nbcol <- 200
vertcol <- cut(t, nbcol)
color = rev(rainbow(nbcol, start = 0/6, end = 4/6))
persp3d(x.si, y.si, z.si, col = color[vertcol], smooth=T)
So wireframe is neither smoothed nor interactive
...and rgl.persp3d is interactive but no smoothed. And I can't have both smoothed and interactive.
r rgl wireframe
r rgl wireframe
edited Jan 17 '17 at 15:30
asked Jan 17 '17 at 15:01
aniusni
346
346
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
rgl
just draws what you give it. You need to use mgcv
as in your first example to do the smoothing, but you don't get a matrix of fitted values back at the end, so you'll want to use deldir
to turn the results into a surface. For example,
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
library(rgl)
library(deldir)
zfit <- fitted(mod)
col <- cm.colors(20)[1 +
round(19*(zfit - min(zfit))/diff(range(zfit)))]
persp3d(deldir(x, y, z = zfit), col = col)
aspect3d(1, 2, 1)
This gives a nice smooth surface, for example
add a comment |
up vote
0
down vote
A simpler way, without the delaunay stuff:
library(mgcv)
x <- rnorm(200)
y <- rnorm(200)
z <- rnorm(200)
tab <- data.frame(x,y,z)
mod <- mgcv::gam(z ~ te(x, y), data = tab)
grid <- -5:5
zfit <- predict(mod, expand.grid(x = grid, y = grid))
persp3d(grid, grid, zfit)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
rgl
just draws what you give it. You need to use mgcv
as in your first example to do the smoothing, but you don't get a matrix of fitted values back at the end, so you'll want to use deldir
to turn the results into a surface. For example,
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
library(rgl)
library(deldir)
zfit <- fitted(mod)
col <- cm.colors(20)[1 +
round(19*(zfit - min(zfit))/diff(range(zfit)))]
persp3d(deldir(x, y, z = zfit), col = col)
aspect3d(1, 2, 1)
This gives a nice smooth surface, for example
add a comment |
up vote
2
down vote
rgl
just draws what you give it. You need to use mgcv
as in your first example to do the smoothing, but you don't get a matrix of fitted values back at the end, so you'll want to use deldir
to turn the results into a surface. For example,
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
library(rgl)
library(deldir)
zfit <- fitted(mod)
col <- cm.colors(20)[1 +
round(19*(zfit - min(zfit))/diff(range(zfit)))]
persp3d(deldir(x, y, z = zfit), col = col)
aspect3d(1, 2, 1)
This gives a nice smooth surface, for example
add a comment |
up vote
2
down vote
up vote
2
down vote
rgl
just draws what you give it. You need to use mgcv
as in your first example to do the smoothing, but you don't get a matrix of fitted values back at the end, so you'll want to use deldir
to turn the results into a surface. For example,
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
library(rgl)
library(deldir)
zfit <- fitted(mod)
col <- cm.colors(20)[1 +
round(19*(zfit - min(zfit))/diff(range(zfit)))]
persp3d(deldir(x, y, z = zfit), col = col)
aspect3d(1, 2, 1)
This gives a nice smooth surface, for example
rgl
just draws what you give it. You need to use mgcv
as in your first example to do the smoothing, but you don't get a matrix of fitted values back at the end, so you'll want to use deldir
to turn the results into a surface. For example,
library(mgcv)
x<- rnorm(200)
y<- rnorm(200)
z<-rnorm(200)
tab<-data.frame(x,y,z)
tab
#surface wireframe:
mod <- gam(z ~ te(x, y), data = tab)
library(rgl)
library(deldir)
zfit <- fitted(mod)
col <- cm.colors(20)[1 +
round(19*(zfit - min(zfit))/diff(range(zfit)))]
persp3d(deldir(x, y, z = zfit), col = col)
aspect3d(1, 2, 1)
This gives a nice smooth surface, for example
answered Jan 17 '17 at 17:20
user2554330
8,35011237
8,35011237
add a comment |
add a comment |
up vote
0
down vote
A simpler way, without the delaunay stuff:
library(mgcv)
x <- rnorm(200)
y <- rnorm(200)
z <- rnorm(200)
tab <- data.frame(x,y,z)
mod <- mgcv::gam(z ~ te(x, y), data = tab)
grid <- -5:5
zfit <- predict(mod, expand.grid(x = grid, y = grid))
persp3d(grid, grid, zfit)
add a comment |
up vote
0
down vote
A simpler way, without the delaunay stuff:
library(mgcv)
x <- rnorm(200)
y <- rnorm(200)
z <- rnorm(200)
tab <- data.frame(x,y,z)
mod <- mgcv::gam(z ~ te(x, y), data = tab)
grid <- -5:5
zfit <- predict(mod, expand.grid(x = grid, y = grid))
persp3d(grid, grid, zfit)
add a comment |
up vote
0
down vote
up vote
0
down vote
A simpler way, without the delaunay stuff:
library(mgcv)
x <- rnorm(200)
y <- rnorm(200)
z <- rnorm(200)
tab <- data.frame(x,y,z)
mod <- mgcv::gam(z ~ te(x, y), data = tab)
grid <- -5:5
zfit <- predict(mod, expand.grid(x = grid, y = grid))
persp3d(grid, grid, zfit)
A simpler way, without the delaunay stuff:
library(mgcv)
x <- rnorm(200)
y <- rnorm(200)
z <- rnorm(200)
tab <- data.frame(x,y,z)
mod <- mgcv::gam(z ~ te(x, y), data = tab)
grid <- -5:5
zfit <- predict(mod, expand.grid(x = grid, y = grid))
persp3d(grid, grid, zfit)
answered Nov 11 at 1:58


dash2
1254
1254
add a comment |
add a comment |
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%2f41700400%2fsmoothing-3d-plot-in-r%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
8egaxize0,m927Cw9km,OjagY,uj3NZtfZ8aE la,kxgkTseagkPxp wTu3K3V2X,BHci,i9TdPjMulUqzb9vu R tjGX,bS dPfG3w3