spacetime: Spatio-temporal maps from incidence objects

Description Usage Arguments Value Author(s) See Also Examples

View source: R/spacetime.R

Description

This function implements similar features to the S4 generic stplot from the spacetime package for incidence objects (from the incidence package), which are stratified by locations.

Usage

1
2
spacetime(obj, sf, type = c("map", "heatmap"), breaks = NULL,
  field = "NAME_2", pal = viridis::viridis, ...)

Arguments

obj

An incidence objects, as generated by the codeincidence package, stratified by geographic units matching that of a provided shapefile.

sf

A shapefile stored as a SpatialPolygonsDataFrame object from the sp package.

type

A character string indicating the type of graphics to produce: a map ("map"), or a heatmap ("heatmap").

breaks

A numeric vector indicating break points for the color scale.

field

A character string indicating the field containing the name of the spatial units to be used for plotting - the same as the ones used for incidence stratification.

pal

A color palette to be used for plotting.

...

Further arguments to be passed to stplot.

Value

The function returns a plot with extra attributes:

Author(s)

Isobel Blake (isobel.blake@imperial.ac.uk) and Thibaut Jombart (thibautjombart@gmail.com)

See Also

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
## Not run: 
if (require("sp") &&
    require("raster") &&
    require("outbreaks") &&
    require("incidence")) {

## fetch shapefiles for different admin levels
adm2data <- raster::getData('GADM', country = 'SLE', level = 2)
adm1data <- raster::getData('GADM', country = 'SLE', level = 1)
adm0data <- raster::getData('GADM', country = 'SLE', level = 0)

## plot data
plot(adm2data, border = "grey")
plot(adm1data, add = TRUE)
plot(adm0data, add = TRUE, lwd = 2)
text(sp::coordinates(adm2data), labels = adm2data$NAME_2, cex = 0.6)

## make fake data
dat <- ebola_sim$linelist

## randomly assign district location
p <- c(0.15,0.1,0.01,0.01,0.02,0,0,0.05,0.01,0,0.05,0.1,0.25,0.25)
dat$adm2 <- sample(adm2data$NAME_2, size = nrow(dat),
                   replace = TRUE, prob = p)

## make an incidence object
x <- incidence::incidence(dat$date_of_onset, 30, groups = dat$adm2)

## make plot
res <- spacetime(x, adm2data)
res

## extra data stored in attributes
attributes(res)
}

## End(Not run)

reconhub/epimaps documentation built on May 7, 2019, 1:30 p.m.