map_ggplot: ggplot2 mapping

View source: R/map_ggplot.R

map_ggplotR Documentation

ggplot2 mapping

Description

ggplot2 mapping

Usage

map_ggplot(
  x,
  map = "world",
  point_color = "#86161f",
  color = NULL,
  size = 3,
  lon = "longitude",
  lat = "latitude",
  name = NULL,
  ...
)

Arguments

x

The data. An object of class occdat, occdatind, gbif, gbif_data, SpatialPoints, SpatialPointsDataFrame, or data.frame. The package spocc needed for the first two, and rgbif needed for the third. When data.frame input, any number of columns allowed, but with at least the following: name (the taxonomic name), latitude (in dec. deg.), longitude (in dec. deg.)

map

(character) One of world, world2, state, usa, county, france, italy, or nz

point_color

Default color of your points. Deprecated, use color

color

Default color of your points.

size

point size, Default: 3

lon, lat

(character) Longitude and latitude variable names. Ignored unless data.frame input to x parameter. We attempt to guess, but if nothing close, we stop. Default: longitude and latitude

name

(character) the column name that contains the name to use in creating the map. If left NULL we look for a "name" column. default: NULL

...

Ignored

Value

A ggplot2 map, of class gg/ggplot

Examples

# map spocc output, here using a built in object
data(occdat_eg1)
map_ggplot(occdat_eg1)

# map rgbif output, here using a built in object
data(gbif_eg1)
map_ggplot(gbif_eg1)

## Not run: 
## spocc
library("spocc")
ddat <- occ(query = 'Lynx rufus californicus', from = 'gbif', limit=100)
map_ggplot(ddat)
map_ggplot(ddat$gbif)
map_ggplot(ddat$gbif, "usa")
map_ggplot(ddat, "county")

### usage of occ2sp()
#### SpatialPoints
spdat <- occ2sp(ddat)
map_ggplot(spdat)
#### SpatialPointsDataFrame
spdatdf <- as(spdat, "SpatialPointsDataFrame")
map_ggplot(spdatdf)

## rgbif
if (requireNamespace("rgbif")) {
library("rgbif")
library("ggplot2")
### occ_search() output
res <- occ_search(scientificName = "Puma concolor", limit = 100)
map_ggplot(res)

### occ_data() output
res <- occ_data(scientificName = "Puma concolor", limit = 100)
map_ggplot(res)

#### many taxa
res <- occ_data(scientificName = c("Puma concolor", "Quercus lobata"), 
   limit = 30)
map_ggplot(res)

### add a convex hull
hull(map_ggplot(res))
}

## data.frame
df <- data.frame(name = c('Poa annua', 'Puma concolor', 'Foo bar'),
                 longitude = c(-120, -121, -121),
                 latitude = c(41, 42, 45), stringsAsFactors = FALSE)
map_ggplot(df)

# many species, each gets a different color
library("spocc")
spp <- c('Danaus plexippus', 'Accipiter striatus', 'Pinus contorta')
dat <- occ(spp, from = 'gbif', limit = 30, has_coords = TRUE)
map_ggplot(dat, color = c('#976AAE', '#6B944D', '#BD5945'))

## End(Not run)

ropensci/spoccutils documentation built on Sept. 12, 2022, 3:03 p.m.