courtiol / IsoriX

This is the GitHub repository dedicated to the development of the R package IsoriX
14 stars 6 forks source link

Sphere 3D #3

Closed courtiol closed 7 years ago

courtiol commented 8 years ago

I looked at how one could make nice 3D geospheres in R using rgl. The following site does not tell the details but the results are stunning, so I really want to add this possibility in the package at some point :-)

link1 link2

It is not that difficult once one has the png of the entire map, I am struggling however to extract the central part of the lattice plots (i.e. the map itself, without the axes, keys, margins...). I want the area selected by trellis.focus()...

Once this will be solved, then the following works:

library(rgl)
map <- rgl.spheres(0, texture="map.png", lit=FALSE)
## for gif movie
movie3d(spin3d(axis = c(0, 1, 0), rpm=2), duration = 30, dir = getwd())
courtiol commented 7 years ago

Try something inspired by that (from Deepayan Sarkar deepayan.sarkar@r-project.org ):

library(grid) library(lattice)

p <- levelplot(volcano) pargs <- trellis.panelArgs(p, 1) lims <- do.call(prepanel.default.levelplot, pargs) str(lims) # viewport scales

Need f = 0.07 below (for reasons that are not important)

grid.newpage() pushViewport(viewport(xscale = extendrange(lims$xlim, f = 0.07), yscale = extendrange(lims$ylim, f = 0.07))) do.call(panel.levelplot, pargs)

courtiol commented 7 years ago

Another way using the package mapmate looks very promising (but potentially slow): https://www.r-bloggers.com/spinning-globes-with-r/

We need to try that too!