sphereplot | R Documentation |
Plots a spherical function or a point set in a 2D projection using only standard R graphics. This avoids compatibility issues of rgl, e.g. knitting markdown documents.
sphereplot(
f = NULL,
n = 100,
theta0 = pi/2,
phi0 = 0,
angle = 0,
projection = "globe",
col = gray.colors(256, 0, 1),
clim = NULL,
add = FALSE,
center = c(0, 0),
radius = 1,
nv = 500,
show.border = TRUE,
show.grid = TRUE,
grid.phi = seq(0, 330, 30)/180 * pi,
grid.theta = seq(30, 150, 30)/180 * pi,
pch = 16,
pt.col = "black",
pt.cex = 0.5,
lwd = 0.5,
lty = 1,
line.col = "black",
background = "white",
...
)
f |
must be either of: (1) NULL to plot just grid without spherical function (2) a vectorized real function f(theta,phi) of the polar angle theta [0,pi] and azimuth angle [0,2pi] (3) an n-by-2 array of values theta and phi |
n |
number of grid cells in each dimension used in the plot |
theta0 |
polar angle in radians at the center of the projection |
phi0 |
azimuth angle in radians at the center of the projection |
angle |
angle in radians between vertical axis and central longitudinal great circle |
projection |
type of projection: "globe" (default), "cylindrical", "mollweide" |
col |
color map |
clim |
2-element vector specifying the values of f corresponding to the first and last color in col |
add |
logical flag specifying whether the sphere is to be added to an existing plot |
center |
center of the sphere on the plot |
radius |
radius of the sphere on the plot |
nv |
number or vertices used for grid lines and border |
show.border |
logical flag specifying whether to show a circular border around the sphere |
show.grid |
logical flag specifying whether to show grid lines |
grid.phi |
vector of phi-values of the longitudinal grid lines |
grid.theta |
vector of theta-values of the latitudinal grid lines |
pch |
point type |
pt.col |
point color |
pt.cex |
point size |
lwd |
line width of grid lines and border |
lty |
line type of grid lines and border |
line.col |
color of grid lines and border |
background |
background color |
... |
additional arguments to be passed to the function f |
Returns a list containing the vector col
of colors and 2-vector clim
of values corresponding to the first and last color.
Danail Obreschkow
## Plot random points on the unit sphere in Mollweide projection
set.seed(1)
f = cbind(acos(runif(5000,-1,1)),runif(5000,0,2*pi))
sphereplot(f,theta0=pi/3,projection='mollweide',pt.col='red')
## Plot real spherical harmonics up to third degree
oldpar = par(mar=c(0,0,0,0))
nplot(xlim=c(-4,3.5),ylim=c(0,4),asp=1)
for (l in seq(0,3)) { # degree of spherical harmonic
for (m in seq(-l,l)) { # order of spherical harmonic
# make spherical harmonic function in real-valued convention
f = function(theta,phi) sphericalharmonics(l,m,cbind(theta,phi))
# plot spherical harmonic
sphereplot(f, 50, col=planckcolors(100), phi0=0.1, theta0=pi/3, add=TRUE, clim=c(-0.7,0.7),
center=c(m,3.5-l), radius=0.47)
if (l==3) text(m,-0.15,sprintf('m=%+d',m))
}
text(-l-0.55,3.5-l,sprintf('l=%d',l),pos=2)
}
par(oldpar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.