plotdap: Visualize rerddap data

Description Usage Arguments Details Author(s) See Also Examples

View source: R/plotdap.R

Description

Visualize data returned from rerddap servers. Use plotdap() to initialize a plot, specify the plotting method (specifically, 'base' or 'ggplot2'), and set some global options/parameters. Then use add_tabledap() and/or add_griddap() to add "layers" of actual data to be visualized.

Add ggplot2 elements to a plotdap object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
plotdap(method = c("ggplot2", "base"), mapData = maps::map("world", plot =
  FALSE, fill = TRUE), crs = NULL, datum = sf::st_crs(4326),
  mapTitle = NULL, mapFill = "gray80", mapColor = "gray90", ...)

add_tabledap(plot, table, var, color = c("#132B43", "#56B1F7"), size = 1.5,
  shape = 19, animate = FALSE, ani.args = list(filename = "ani.gif"), ...)

add_griddap(plot, grid, var, fill = "viridis", maxpixels = 10000,
  time = mean, animate = FALSE, ani.args = list(filename = "ani.gif"),
  ...)

add_ggplot(plot, ...)

Arguments

method

the plotting method. Currently ggplot2 and base plotting are supported.

mapData

an object coercable to an sf object via st_as_sf().

crs

a coordinate reference system: integer with the epsg code, or character with proj4string.

datum

crs that provides datum to use when generating graticules. Set to NULL to hide the graticule.

mapTitle

a title for the map.

mapFill

fill used for the map.

mapColor

color used to draw boundaries of the map.

...

for plotdap()/add_tabledap()/add_griddap(), arguments passed along to geom_sf() (if method='ggplot2', otherwise ignored). For add_ggplot2(), these arguments may be any object of class "gg" (e.g, theme(), scale_fill_gradientn(), geom_point(), etc.)

plot

a plotdap object.

table

a tabledap object.

var

a formula defining a variable, or function of variables to visualize.

color

either a character string of length 1 matching a name in colors or a vector of color codes. This defines the colorscale used to encode values of var.

size

the size of the symbol.

shape

the shape of the symbol. For valid options, see the 'pch' values section on points. plot(0:25, 0:25, pch = 0:25) also gives a quick visual of the majority of possibilities.

animate

whether to animate over the time variable (if it exists). Currently only implemented for method='ggplot2' and requires the gganimate package.

ani.args

arguments passed along to gganimate().

grid

a griddap object.

fill

either a character string of length 1 matching a name in \link[rerddap]colors or a vector of color codes. This defines the colorscale used to encode values of var.

maxpixels

integer > 0. Maximum number of cells to use for the plot. If maxpixels < ncell(x), sampleRegular is used before plotting. If gridded=TRUE maxpixels may be ignored to get a larger sample

time

how to resolve multiple time frames. Choose one of the following:

  • A function to apply to each observation at a particular location (mean is the default).

  • A character string (of length 1) matching a time value.

Details

The "ggplot2" method is slower than "base" (especially for high-res grids/rasters), but is more flexible/extensible. Additional ggplot2 layers, as well as scale defaults, labels, theming, etc. may be modified via the add_ggplot() function. See the mapping vignette for an introduction and overview of rerrdap's visualization methods – browseVignettes(package = "rerddap").

Author(s)

Carson Sievert

See Also

tabledap(), griddap()

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
# base plotting tends to be faster (especially for grids), but is less extensible
plotdap("base")

## Not run: 
# tabledap examples
sardines <- tabledap(
  'FRDCPSTrawlLHHaulCatch',
  fields = c('latitude',  'longitude', 'time', 'scientific_name', 'subsample_count'),
  'time>=2010-01-01', 'time<=2012-01-01', 'scientific_name="Sardinops sagax"'
 )

p <- plotdap()
add_tabledap(p, sardines, ~subsample_count)
add_tabledap(p, sardines, ~log(subsample_count))

# using base R plotting
p <- plotdap("base")
add_tabledap(p, sardines, ~subsample_count)

# robinson projection
p <- plotdap(crs = "+proj=robin")
add_tabledap(p, sardines, ~subsample_count)

# griddap examples
murSST <- griddap(
  'jplMURSST41', latitude = c(22, 51), longitude = c(-140, -105),
  time = c('last', 'last'), fields = 'analysed_sst'
 )
p <- plotdap(crs = "+proj=robin")
add_griddap(p, murSST, ~analysed_sst)

# layer tables on top of grids
plotdap("base") %>%
  add_griddap(murSST, ~sst) %>%
  add_tabledap(sardines, ~subsample_count)

# multiple time periods
wind <- griddap(
  'erdQMwindmday', time = c('2016-11-16', '2017-01-16'),
  latitude = c(30, 50), longitude = c(210, 240),
  fields = 'x_wind'
)
p <- plotdap("base", mapTitle = "Average wind over time")
add_griddap(p, wind, ~x_wind)


## End(Not run)

library(ggplot2)

add_ggplot(
 plotdap(
   crs = "+proj=laea +y_0=0 +lon_0=155 +lat_0=-90 +ellps=WGS84 +no_defs",
   mapColor = "black"
 ),
 theme_bw()
)

ropensci/plotdap documentation built on Sept. 7, 2017, 3:37 a.m.