Learn R Programming

mapr (version 0.5.2)

map_plot: Base R mapping

Description

Base R mapping

Usage

map_plot(
  x,
  lon = "longitude",
  lat = "latitude",
  color = NULL,
  size = 1,
  pch = 16,
  hull = FALSE,
  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.)

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

color

Default color of your points.

size

point size, passed to cex Default: 1

pch

point symbol shape, Default: 16

hull

(logical) whether to add a convex hull. Default: FALSE

name

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

...

Further args to graphics::points()

Value

Plots a world scale map

Examples

Run this code
# NOT RUN {
# map spocc output, here using a built in object
data(occdat_eg1)
map_plot(occdat_eg1)

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

# }
# NOT RUN {
## spocc
library("spocc")
(out <- occ(query='Accipiter striatus', from='gbif', limit=25,
  has_coords=TRUE))
### class occdat
map_plot(out)
map_plot(out, hull = TRUE)
### class occdatind
map_plot(out$gbif)
map_plot(out$gbif, hull = TRUE)

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

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


## data.frame
df <- data.frame(
  name = c('Poa annua', 'Puma concolor', 'Foo bar', 'Stuff things'),
  longitude = c(-125, -123, -121, -110),
  latitude = c(41, 42, 45, 30), stringsAsFactors = FALSE)
map_plot(df)
map_plot(df, hull = TRUE)

### usage of occ2sp()
#### SpatialPoints
spdat <- occ2sp(out)
map_plot(spdat)
map_plot(spdat, hull = TRUE)

#### SpatialPointsDataFrame
spdatdf <- as(spdat, "SpatialPointsDataFrame")
map_plot(spdatdf)
map_plot(spdatdf, hull = TRUE)

# many species, each gets a different color
library("spocc")
spp <- c('Danaus plexippus', 'Accipiter striatus', 'Pinus contorta',
  'Ursus americanus')
dat <- occ(spp, from = 'gbif', limit = 30, has_coords = TRUE,
  gbifopts = list(country = 'US'))
map_plot(dat)
map_plot(dat, hull = TRUE)
## diff. color for each taxon
map_plot(dat, color = c('#976AAE', '#6B944D', '#BD5945', 'red'))
map_plot(dat, color = c('#976AAE', '#6B944D', '#BD5945', 'red'), hull = TRUE)

# add a convex hull
if (requireNamespace("rgbif")) {
library("rgbif")
res <- occ_search(scientificName = "Puma concolor", limit = 100)
map_plot(res, hull = FALSE)
map_plot(res, hull = TRUE)
}
# }

Run the code above in your browser using DataLab