R: geocontour.fill plots colored or black and white contours on...
geocontour.fill
R Documentation
geocontour.fill plots colored or black and white contours on a graph made by
geoplot.
Description
The program accepts data on a rectangular grid. Irregular data can be
interpolated on the grid in a number of ways, using kriging, the Splus
function interp, etc. NA's are allowed in the matrix but they are changed
to 0 or the average value of z early in the program. The geo package
contains two different contour plot programs, geocontour and
geocontour.fill. Geocontour draws contour lines and geocontour.fill fills
in between the lines. Hardcopy of the plot can be done on a color
postscript printer or on a black and white postscript printer. In all cases
the "postscript" driver included with Splus has to be used. There is
another postscript driver included with Splus called "pscript". That driver
is used when a plot is on the screen and the print button is pressed. That
can not be done when the postscript driver is used as described here after.
List with components $lat and $lon (or $x, $y) defining the
grid values. Can be made for example by lat <- list(lat = seq(60, 65,
length = 100), lon = seq(-30, - 10, length = 200)). Also lat can be the
outcome of the program grid and then the components lat$grpt$lat,
lat$grpt$lon and lat$reg are used.
z
Matrix or vector of values. Length(z) = nlat*nlon except when lat
is a list with components lat$grpt and lat$xgr. Then the length of z is
the same as the length of lat$xgr$lat and lat$xgr$lon. This is the case
if the output of the grid program is used as input lat.
levels
Values at contourlines. Default value is zero. If levels is
zero the program determines the contourlines from the data. If levels is of
length 3 with levels = c(0, 1, 2) then there are 4 groups each with special
color i.e. <0, 0-1, 1-2 and > 2.
nlevels
Number of contourlines. Used if the program has to determine
the contourlines. Default value is 10. nlevels = 10 does not always mean
10 due to characteristic of the pretty command.
cex
Character size expansion. Size of letters in labels. Default
value is 0.7.
digits
Number of digits in the labels. Default value is 1.
col
Color number for the contourlines. A vector one longer than the
vector levels Default is blue-green- yellow-red from lowest to the highest
values. The program assumes certain setup of the splus colors that is
described later. Colors should not be specified explicitly except the
contour lines are.
working.space
Size of working space. The program determines it from
data and prints on the screen. If mysterious errors occur then it is likely
that the program has not reserved enough working space. The program writes
the used work space on the screen for use in similar situations. (saves
time.)
labels
Type of labels, either 1 or 2 <s-example>
labels = 1 means type of label used with few contourlines <20. labels = 2
means type of label used with many contourlines >20. can also use labels =
3 means only labels, no contour plot.
</s-example> Labels can be inserted in two ways, by calling geoplot with
cont = TRUE or by specifying label.location. In the first case the left
part of the plot is reserved for labels while in the latter case the label
is put in a place specified by the user. The latter method is recommended
in most cases.
ratio
Factor used to avoid numerical problems. Default value 100.
Lower values decrease numerical problems but can introduce bias.
only.positive
Logical value. If TRUE then negative values are not
allowed else negative values are set to zero. Default value is FALSE.
fill
Determines whether NA's should be replaced with zeros (fill = 1)
or mean(z) (fill = 2). Default value is fill = 1. Used when lat is a list
with components lat$xgr$lat, lat$xgr$lon, lat$grpt$lat and
lat$grpt$lon. Only used in special cases.
maxcol
Number of colors used (excluding #0). Default value 155.
white
If true the the first class is represented with white (color
0). Default value is FALSE but white = TRUE is also often used.
label.location
List with components $lat and $lon. (or $x, $y)
Gives the lower left and upper right corner of the box where the labels are
put. Default value is 0 that means no labels are put on the drawing (except
when geopar$cont = TRUE). l1 is best given by geolocator or directly by
specifying label.location = "locator".
labels.only
If labels.only is true no contours are drawn but only
labels. Default value is false. Order of the commands could be:
<s-example> > geoplot(deg, plot = FALSE) > geocontour.fill(lat, z = z,
levels = lev, reg = area) # Draw contours. > geocontour(lat, z = z, levels
= lev, colors = FALSE, reg = area) # Only used with black and white printers
to make distinction # between different levels clearer. (not used with
color # printers). > geoplot(deg, new = TRUE) # Refresh gridlines. >
geocontour.fill(lat, z = z, levels = lev, labels.only = TRUE, label.location
= l1) # Add labels. </s-example>
bordercheck
if true the program checks if plot is outside border and
does not plot what is outside border.
maxn
a parameter determing the resolution of the plot, unimportant.
bcrat
bordercheck ratio, how much outside the border we will allow to
be plotted, default is bcrat = 0.05 meaning that we will allow the plot to
go 5% off the border.
limits
To be described.
col.names
the names of the columns in grid, the first argument will
be plotted on the x-axes and the second on the y-axes. Default is col.names
= c("lat", "lon").
minsym
minimum symbol, default is "<", meaning that if levels = c(1,
2), labels will be presented as < 1, 1-2, 2 <, but if minsym = " " labels
will be presented as 1, 1-2, 2. See also labels.resolution.
label.resolution
the resolution (precision) of the label numbers,
default is 0, meaning that if levels = c(1, 2), labels will be presented <
1, 1-2, 2 <, if label.resolution = 0.1 labels will be presented < 1, 1.1-2,
2.1<, see also minsym. If label.resolution = "none", the labels will
present the lowest number of the interval with each color.
labtxt
To be described.
boxcol
Colour of box around labels (legend?).
first.color.trans
To be described.
mai
par argument 'margin in inches'?
leftrat
To be described.
labbox
should a box be drawn around labels (legend?).
csi
Size of character. This parameter can not be set in R but for
compatibility with old Splus scripts the parameter cex is readjusted by cex
= cex*csi/0.12. Use of this parameter is not recommended. Default value is
NULL i.e not used.
Details
<s-example>
The program is based on making triangles out of a matrix of data nx * ny.
The number of triangles is (nx-1)*(ny- 1)*4 and linear interpolation is used
inside each triangle. The factor 4 comes from the fact that the number of
points is doubled by interpolation. </s-example> <s-example>
Most of the calculations in the program are done by a program written in C.
The Splus part of the program prepares the data for the C program, reserves
memory and the user interface is in Splus. The C program is loaded
automatically. </s-example> <s-example>
The program is currently based on the following color setup in Splus.
</s-example> <s-example>
splus*color : white black blue 50 green 50 yellow 50 red </s-example>
<s-example>
This gives 155 colors with color#0 white, #1 black, #2 blue, #53 green, #104
yellow, and #155 red. The parameter maxcol is set to 155 based on this
setup but it can be changed if another setup is used. The vector postcol
stores the mapping from the colors on the terminal to color postscript based
on this setup. </s-example> <s-example>
If the openlook() or motif() windowmanager is used in Splus the colors can
be changed inside Splus. In openlook it is best to make a colorscheme
called geoplot: black blue 50 green 50 yellow 50 red. The background color,
i.e. white is not in the definition here. </s-example> <s-example>
The maximum number of contourlines that can be used is currently 60.
</s-example> <s-example>
The program requires that geoplot is called before to set up the drawing.
geoplot is called by the parameter cont = TRUE. This is to reserve space for
labels on the drawing. </s-example> <s-example>
If the drawing is written to a file geoplot should be called with plot =
FALSE. Then it only sets up the drawing but does not plot anything so the
size of the file will be reduced. </s-example> <s-example>
If the labels do not fit the relative space taken by labels and picture can
be changed by the parameter lcont in geoplot. After geocontour.fill is
called geoplot is called again with new = TRUE to get all kind of lines back
but they were painted over by the program. </s-example> <s-example>
The program treats borders in a special way. It begins by making
contour-lines over the hole area as if the borders did not exist. When that
is finished the area outside the borders is painted white. </s-example>
<s-example>
If good picture is needed geocontour should be used between levels to get
sharper pictures. </s-example> <s-example>
If the matrix z is not full the program should be called by a list
lat$xgr$lat, lat$xgr$lon, lat$grpt$lat and lat$grpt$lon. Then the
length of the vectors z, lat$xgr$lat and lat$xgr$lon is the same.
lat$grpt$lat and lat$grpt$lon is on the other hand the coordinates of
the rows and columns of the matrix. The program grid makes a list with
components with these names. </s-example> <s-example>
The functions geolines, geopoint, geopolygon, geotext & geosymbols can be
used to add things to the contourplot. </s-example>