## 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)
Run the code above in your browser using DataLab