ggspatial (version 0.2.1)

geom_spatial: A ggplot2 geom for Spatial* objects

Description

A function returning a geom_* object based on the Spatial* input. Also will happily project a regular data.frame provided x and y aesthetics are specified. The result is a geom_* for use with ggplot2, with aesthetics and other argumets passed on to that geom.

Usage

geom_spatial(data, ...)

ggspatial(data, mapping = NULL, ...)

# S3 method for default geom_spatial(data, mapping = NULL, show.legend = TRUE, inherit.aes = NULL, position = "identity", crsfrom = NA, crsto = NA, geom = "point", ...)

# S3 method for SpatialPoints geom_spatial(data, mapping = NULL, show.legend = TRUE, inherit.aes = NULL, position = "identity", crsfrom = NA, crsto = NA, attribute_table = NULL, ...)

# S3 method for SpatialPointsDataFrame geom_spatial(data, mapping = NULL, show.legend = TRUE, inherit.aes = NULL, position = "identity", crsfrom = NA, crsto = NA, ...)

# S3 method for SpatialLines geom_spatial(data, mapping = NULL, show.legend = TRUE, inherit.aes = NULL, position = "identity", crsfrom = NA, crsto = NA, attribute_table = NULL, ...)

# S3 method for SpatialLinesDataFrame geom_spatial(data, mapping = NULL, show.legend = TRUE, inherit.aes = NULL, position = "identity", crsfrom = NA, crsto = NA, ...)

# S3 method for SpatialPolygons geom_spatial(data, mapping = NULL, show.legend = TRUE, inherit.aes = NULL, position = "identity", crsfrom = NA, crsto = NA, rule = "winding", attribute_table = NULL, ...)

# S3 method for SpatialPolygonsDataFrame geom_spatial(data, mapping = NULL, show.legend = TRUE, inherit.aes = NULL, position = "identity", crsfrom = NA, crsto = NA, rule = "winding", ...)

Arguments

data

A Spatial* object or data.frame.

...

Agruments passed on to the geom_* (e.g. lwd, fill, etc.)

mapping

A mapping as created by aes() or aes_string()

show.legend

Logical describing the legend visibility.

inherit.aes

Logical describing if aesthetics are inherited

position

Passed on to geom_*

crsfrom

An object that can be coerced to a CRS using as.CRS; defaults to the CRS of the data or lat/lon if that does not exist

crsto

An object that can be coerced to a CRS using as.CRS; defaults to lat/lon so that the plot can be projected using coord_map()

geom

For data frames, the geometry to use

attribute_table

For SpatialPoints, SpatialLines, and SpatialPolygons, an attribute table that matches the input object.

rule

One of 'evenodd' or 'winding', if the Spatial object is a polygon layer.

Value

A ggplot2 'layer' object.

Examples

Run this code
# NOT RUN {
library(prettymapr)
ns <- searchbbox("Nova Scotia")
cities <- geocode(c("Wolfville, NS", "Windsor, NS", "Halifax, NS"))
ggplot(cities, aes(x=lon, y=lat)) + geom_spatial(crsto=26920)
# default projection is Spherical Mercator (EPSG:3857)
ggplot(cities, aes(x=lon, y=lat)) + geom_spatial() + coord_map()
# }
# NOT RUN {
# plot a number of spatial objects
ggplot() +
  geom_spatial(longlake_waterdf, fill="lightblue") +
  geom_spatial(longlake_marshdf, fill="grey", alpha=0.5) +
  geom_spatial(longlake_streamsdf, col="lightblue") +
  geom_spatial(longlake_roadsdf, col="black") +
  geom_spatial(longlake_buildingsdf, pch=1, col="brown", size=0.25) +
  coord_map()

# }

Run the code above in your browser using DataLab