map_plot: Base R mapping

Description Usage Arguments Value Examples

View source: R/map_plot.R

Description

Base R mapping

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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

 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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)
}

## End(Not run)

mapr documentation built on Oct. 23, 2020, 8:22 p.m.