Learn R Programming

magicaxis (version 2.0.0)

magproj: Magic longitude / latitude projection function

Description

High level methods for producing pretty plot of projected data. Particularly useful in astronomy or geography, where many datasets are in longitude (right ascension) / latitude (declination) format. magproj is the highest level function, creating a projected image grid with labels and data. magprojgrid and magprojlabels are functions to simply overplot a grid and add labels respectively.

Usage

magproj(long, lat, type = "b", plottext, longlim = c(-180, 180), latlim = c(-90, 90), projection = "aitoff", parameters = NULL, centre = c(0, 0), add = FALSE, fliplong=FALSE, nlat=6, nlong=6, prettybase=30, labels = TRUE, grid=TRUE, grid.col = "grey", grid.lty = 2, auto = FALSE, upres = 100, box = TRUE, labloc = c(90, -45), labeltype = "deg", crunch=FALSE, ...) magprojgrid(nlat=6, nlong=6, prettybase=30, box=TRUE, ...) magprojlabels(nlat=6, nlong=6, prettybase=30, labloc = c(90, -45), labeltype='deg', crunch=FALSE, ...)

Arguments

long
Vector of longitude values to use. If this is a matrix or data.frame with two columns and lat is missing then column 1 is taken to be longitude values and column 2 is taken to be latitude values. long should have 2 elements only when type="b".
lat
Vector of latitude values to use. If the input for long is a matrix or data.frame with two columns and lat is missing then column 1 is taken to be longitude values and column 2 is taken to be latitude values. lat should have 2 elements only when type="b".
type
The display type, either points (p), lines (l), polygon (pl), text (t), or box (b, the default). Points simply projects longitude and latitude positions into particle positions. Lines will join the positions together into a line, using approxfun to interpolate between positions at resolution upres. Polygon will join the positions together into a polygon, using approxfun to interpolate between positions at resolution upres. Text will display the text provided in plottext at the positions. Box will draw a polygon box, where the limits are given as a two element vector for long and a two element vector for lat.
plottext
A vector of text to display at the provided longitude and latitude positions. Only used if type='t'.
longlim
The longitude limits to use in the plot. Vector of length 2.
latlim
The latitude limits to use in the plot. Vector of length 2.
projection
Map projection to use. This function directly uses mapproject, and all of the inputs allowed for the projection argument in that function are also allowed here.
parameters
Map parameters to use. For details see the parameters argument in mapproject.
centre
For most popular projections this argument specifies the longitude and latitude that is centred in the plot. Strictly orientation in mapproject is set to c(90+centre[2], centre[1], 0).
add
Should a fresh plot be drawn (add=FALSE), or should the new data be added to the current plot (add=TRUE).
fliplong
Should the the longitude axis be flipped so that low values are on the right hand side (normal for celestial sphere plots in astronomy).
nlong
The target number of gridlines in the longitude direction. Uses pretty, so the result may not be what is requested.
nlat
The target number of gridlines in the latitude direction. Uses pretty, so the result may not be what is requested.
prettybase
The unit of repitition desired for the grid lines and labels. See prettybase in maglab. By default it is 30, implying a pretty plot is one with marks at 30, 60, 90 etc (i.e. attractive for large scale plots covering large longitude and latitude limits).
labels
Should text coordinate labels be added to the plot.
grid
Should a background grid be drawn.
grid.col
The colour of the background grid.
grid.lty
The line type for the background grid.
auto
If auto=FALSE the plot is set up using all options specified. If auto=TRUE then longlim, latlim, centre and labloc is estimated from the data. This mostly behaves sensibly, but do not be too surprised if the automatic plot is not ideal, and some manual tweaking is required.
upres
The resolution at which to do internal interpolation when drawing lines and boxes.
box
Should a black outline be drawn following the longlim and latlim limits.
labloc
The longitude and latitude at which labels should be drawn.
labeltype
Should the labels be drawn using degrees (deg) or column delimited sexigesimal (sex).
crunch
If set to FALSE the full output of deg2hms and deg2dms is printed. If set to TRUE a simplified output is used, where only the hours and degrees parts are extracted and appended with a 'h' and a degree symbol respectively.
...
For magproj, Extra options that are either passed to points (type='p'), lines (type='l'), polygon (type='pl'), text (type='t'), or polygon (type='b'). For magprojgrid dots are pased to lines for drawing the grid lines. For magprojlabels dots are passed to text for adding text labels.

Value

No output. Run for the side effect of producing nice projected plots.

See Also

magplot, magaxis, maglab, magmap, magrun, magbar, magprojextra

Examples

Run this code
# GAMA fields:
par(mar=c(0.1,0.1,0.1,0.1))
magproj(c(129,141), c(-2,3), type='b', projection='aitoff', centre=c(180,0),
fliplong=TRUE, labloc=c(90,-45), col='red', labeltype = 'sex', crunch=TRUE)
magproj(c(211.5,223.5), c(-2,3), col='red', add=TRUE)
magproj(c(30.2,38.8), c(-10.25,-3.72), col='red', add=TRUE)
magproj(c(30.2,38.8), -6, type='l', add=TRUE, col='grey')
magproj(c(339,351), c(-35,-30), col='red', add=TRUE)

magecliptic(width=10,col=hsv(1/12,alpha=0.3),border=NA)
magecliptic(width=0,col='orange')
magMWplane(width=20,col=hsv(v=0,alpha=0.1),border=NA)
magMWplane(width=0,col='darkgrey')
magMW(pch=16, cex=2, col='darkgrey')
magsun(c(7,26), pch=16, cex=2, col='orange2') #An important date!

magproj(c(174,186), c(-3,2), col='red', add=TRUE)

#Plus SDSS:
magproj(c(110,260), c(-4,70), border='blue', add=TRUE)

magproj(c(35,135,180,217.5,345), c(-3.72,3,2,3,-30)+10, type='t',
plottext=c('G02','G09','G12','G15','G23'), add=TRUE)

legend('topleft', legend=c('GAMA Regions','SDSS Main Survey'), col=c('red','blue'),
pch=c(15,NA), lty=c(NA,1), bty='n')
legend('topright', legend=c('Ecliptic','MW Plane'), col=c(hsv(c(1/12,0), v=c(1,0),
alpha=0.5)), pch=c(15,15), lty=c(1,1), bty='n')
legend('bottomleft', legend=c('Sun', 'MW Centre'), col=c('orange2','darkgrey'), pch=16,
bty='n')

Run the code above in your browser using DataLab