psbar function

Add Bars to GMT Mercator Map

Add Bars to GMT Mercator Map

Call GMT to add bars to a map and save in postscript format.

psbar(x, cmd="-J -R -W1p -G180 -O -K", file=getOption("gmt.file"), ref=0, digits=getOption("digits"))

Arguments

  • x: data frame, matrix, or filename containing the data to be plotted.
  • cmd: string of arguments passed to GMT shell command psxy .
  • file: filename where the map is saved.
  • ref: reference latitude where height 1 renders a bar 1 degree high.
  • digits: precision used when rounding the geographic coordinates.

Details

The data are arranged in four columns: Lon, Lat, Width, and Height, in that order.

If x is a filename, the data should be tabular with or without a header, separated by commas or whitespace. The first line is interpreted as header if the first non-whitespace character is not minus, point, or number.

This function provides an alternative to psxy -Sb and psxy -Sr for drawing bars on a Mercator map. See the GMT documentation for details on psxy and other GMT commands.

Returns

Null, but the map is annotated and saved in postscript format.

The temporary GMT input file bar.gmt is saved in directory dirname(tempdir()), for the user to view or edit. It is later removed by psclose().

Note

This function does the necessary calculations to draw bars in standard height given a Mercator-projected map. It is not intended for other projections.

The derivative of the Mercator projection is used to standardize the bar height:

f ⁣(θ)  =  12tan   ⁣ ⁣ ⁣( ⁣π4 ⁣+ ⁣θ2 ⁣)cos2 ⁣( ⁣π4 ⁣+ ⁣θ2 ⁣)f(N)=1/(2tan(pi/4+N/2)cos(pi/4+N/2)2) f'\!(\theta) \;=\; \frac{1}{2\tan\;\!\!\!\Big(\!\frac\pi4\!+\!\frac\theta2\!\Big)\cos^2\!\Big(\!\frac\pi4\!+\!\frac\theta2\!\Big)}f'(N) = 1 / (2 * tan(pi/4+N/2) * cos(pi/4+N/2)^2)

where NN is latitude in radians and f(N)f(N)

is the y-axis coordinate. The bar height at a given latitude is hf(ref)/f(N)h*f'(ref)/f'(N), where hh is the height passed by the user and refref is a reference latitude where h=1h=1 renders a bar 1 degree high.

See Also

Similar to barplot and postscript in native graphics.

gmt, pscoast, psxy, pstext, psbar, and psclose work together to draw maps.

gmt-package gives an overview of the package.

Examples

## Not run: # Draw map and save as "map.ps" in R working directory gmt(demo.par) pscoast(demo.coast) psxy(demo.xy) pstext(demo.text, "-J -R -F+f+a+j -O -K") psbar(demo.bar, ref=66) psclose() # See directory gmt/example for details ## End(Not run)