Learn R Programming

ggsn (version 0.5.0)

north: North symbol

Description

Adds a north symbol to maps created with ggplot or ggmap.

Usage

north(data = NULL, location = "topright", scale = 0.1, symbol = 1,
  x.min, x.max, y.min, y.max, anchor = NULL)

Arguments

data

the same data.frame passed to ggplot to plot the map.

location

string indicating the symbol's location in the plot. Possible options: "topright" (default), "bottomright", "bottomleft" and "topleft".

scale

number between 0 and 1 to indicate the symbol size as a proportion of the map size (bounding box).

symbol

number between 1 and 18 to choose a symbol (see northSymbols).

x.min

if data is not defined, number with the minimum x coordinate. Useful for ggmap.

x.max

if data is not defined, number with the maximum x coordinate. Useful for ggmap.

y.min

if data is not defined, number with the minimum y coordinate. Useful for ggmap.

y.max

if data is not defined, number with the maximum y coordinate. Useful for ggmap.

anchor

named vector with coordinates to control the symbol position. For location = "topright", anchor defines the coordinates of the symbol's topright corner and so forth. The x coordinate must be named as x and the y coordinate as y.

Details

North symbols are included in the plot with the annotation_custom function, which do not works when used together with an empty call to ggplot (see last example). When it is convenient to use an empty call to ggplot, use north2 instead.

Examples

Run this code
# NOT RUN {
library(sf)
data(domestic_violence)
ggplot(domestic_violence, aes(fill = Scaled)) +
    geom_sf() +
    north(domestic_violence, location = "bottomright", symbol = 15) +
    scale_fill_continuous(low = "#fff7ec", high = "#7F0000")
# }

Run the code above in your browser using DataLab