geocoord_format: Geographic coordinate number formatters

Description Usage Arguments Details Value See Also Examples

Description

lat_coord and lon_coord are wrappers of number to format the geographic coordinate values. coord_format is a function factory to produce formatter functions.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
lat_coord(x, accuracy = 1, scale = 1, prefix = c(pos = "", zero = "",
  neg = ""), unit = "°", sep = "", suffix = c(pos = "N", zero = "",
  neg = "S"), big.mark = " ", decimal.mark = ".", trim = TRUE, ...)

lon_coord(x, accuracy = 1, scale = 1, prefix = c(pos = "", zero = "",
  neg = ""), unit = "°", sep = "", suffix = c(pos = "E", zero = "",
  neg = "W"), big.mark = " ", decimal.mark = ".", trim = TRUE, ...)

coord_format(accuracy = 1, scale = 1, prefix = c(pos = "", zero = "",
  neg = ""), unit = "°", sep = " ", suffix = c(pos = "", zero = "",
  neg = ""), big.mark = " ", decimal.mark = ".", trim = TRUE, ...)

Arguments

x

numeric vector to format

accuracy

Number to round to, NULL for automatic guess.

scale

A scaling factor: x will be multiply by scale before formating (useful if the underlying data is on another scale, e.g. for computing percentages or thousands).

prefix

Symbols to display before and after value. By default, it is a named character vector c(pos="", zero="", neg=""). If not in such format, the function will automatically format the prefix.

unit

The units to append.

sep

The separator between the number and the unit label.

suffix

Symbols to display before and after value. By default, it is a named character vector c(pos="N", zero="", neg="S") for 'lat' and c(pos="E", zero="", neg="W") for 'lon'. If not in such format, the function will automatically format the suffix.

big.mark

Character used between every 3 digits to separate thousands.

decimal.mark

The character to be used to indicate the numeric decimal point.

trim

Logical, if FALSE, values are right-justified to a common width (see format()).

...

Other arguments passed on to format().

Details

coord_format is especially useful when plotting maps with ggplot2. The scale_x_continuous() and scale_y_continuous function accepts functions as arguments breaks and labels. You can contruct your own formatter function using coord_format.

Value

a character vector

See Also

number_format() is a function factory to produce functions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 
lat_coord(c(-10, 0, 20), sep=' ', unit='deg')
# [1] "10 degS" "0 deg"   "20 degN"

lat_coord(c(-10, 0, 20), sep=' ', prefix=c(
    pos='S.lat', zero='', neg='N.lat'), suffix='', unit='deg')
# [1] "N.lat10 deg" "0 deg"       "S.lat20 deg"

## End(Not run)
## Not run: 
lon_coord(c(-10, 0, 20), sep=' ', unit='deg')
# [1] "10 degW" "0掳"   "20 degE"

lon_coord(c(-10, 0, 20), sep=' ', prefix=c(
    pos='E.lon', zero='', neg='W.lon'), suffix='', unit='deg')
# [1] "W.lon10 deg" "0 deg"       "E.lon20 deg"

## End(Not run)
## Not run: 

# --------construct a function factory------------
library(ggplot2)
ggplot(aes(long, lat, group=group), data=map_data('usa')) + geom_path() +
  scale_x_continuous(labels=lon_coord) + scale_y_continuous(labels=lat_coord)

## define new formatter functions
lon_lbl <- function(x, ...) 
   coord_format(prefix=c(pos='East', zero='', neg='West'), 
                unit='deg', sep=' ', suffix='', ...)(x)
lat_lbl <- function(x, ...)
   coord_format(prefix=c(pos='North', zero='', neg='South'), 
                unit='deg', sep=' ', suffix='', ...)(x)
ggplot(aes(long, lat, group=group), data=map_data('usa')) + geom_path() +
  scale_x_continuous(labels=lon_lbl) + scale_y_continuous(labels=lat_lbl)

## End(Not run)

madlogos/asesgeo documentation built on Aug. 9, 2019, 9:53 a.m.