Title: | Easily Visualize Data from 'ERDDAP' Servers via the 'rerddap' Package |
---|---|
Description: | Easily visualize and animate 'tabledap' and 'griddap' objects obtained via the 'rerddap' package in a simple one-line command, using either base graphics or 'ggplot2' graphics. 'plotdap' handles extracting and reshaping the data, map projections and continental outlines. Optionally the data can be animated through time using the 'gganmiate' package. |
Authors: | Carson Sievert [aut], Roy Mendelssohn [aut, ctb, cre] |
Maintainer: | Roy Mendelssohn <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.3 |
Built: | 2024-11-11 03:31:17 UTC |
Source: | https://github.com/rmendels/plotdap |
add_ggplot
allows for plotdap ggplot maps to be modified by
further ggplot2 settings
add_ggplot(plot, ...)
add_ggplot(plot, ...)
plot |
a plotdap object. |
... |
arguments passed along to |
A plotdap object
p <- plotdap( crs = "+proj=laea +y_0=0 +lon_0=155 +lat_0=-90 +ellps=WGS84 +no_defs") p <- add_ggplot( p, ggplot2::theme_bw() )
p <- plotdap( crs = "+proj=laea +y_0=0 +lon_0=155 +lat_0=-90 +ellps=WGS84 +no_defs") p <- add_ggplot( p, ggplot2::theme_bw() )
add_griddap
adds the data from an 'rerddap::griddap() call to
a 'plotdap' map
add_griddap( plot, grid, var, fill = "viridis", maxpixels = 10000, time = mean, animate = FALSE, cumulative = FALSE, ... )
add_griddap( plot, grid, var, fill = "viridis", maxpixels = 10000, time = mean, animate = FALSE, cumulative = FALSE, ... )
plot |
a plotdap object. |
grid |
a griddap object. |
var |
a formula defining a variable, or function of variables to visualize. |
fill |
either a character string of length 1 matching a name in the
package |
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:
|
animate |
whether to animate over the |
cumulative |
- if animation should be cumulative -default FALSE |
... |
arguments passed along to |
A plotdap object
# base plotting tends to be faster, # but is less extensible plotdap("base") # actual datasets in data folder to meet execution timings # murSST <- rerddap::griddap( # ' jplMURSST41', latitude = c(35, 40), longitude = c(-125, -120.5), # time = c('last', 'last'), fields = 'analysed_sst' # ) # QMwind <- rerddap::griddap( # 'erdQMwindmday', time = c('2016-11-16', '2017-01-16'), # latitude = c(30, 50), longitude = c(210, 240), # fields = 'x_wind' # ) p <- plotdap(crs = "+proj=robin") p <- add_griddap(p, murSST, ~analysed_sst) # p <- plotdap(mapTitle = "Average wind over time") # p <- add_griddap(p, QMwind, ~x_wind) # p <- plotdap("base", crs = "+proj=robin") # p <- add_griddap(p, murSST, ~analysed_sst) # layer tables on top of grids require(magrittr) p <- plotdap("base") %>% add_griddap(murSST, ~analysed_sst) %>% add_tabledap(sardines, ~subsample_count) # multiple time periods p <- plotdap("base", mapTitle = "Average wind over time") p <- add_griddap(p, QMwind, ~x_wind)
# base plotting tends to be faster, # but is less extensible plotdap("base") # actual datasets in data folder to meet execution timings # murSST <- rerddap::griddap( # ' jplMURSST41', latitude = c(35, 40), longitude = c(-125, -120.5), # time = c('last', 'last'), fields = 'analysed_sst' # ) # QMwind <- rerddap::griddap( # 'erdQMwindmday', time = c('2016-11-16', '2017-01-16'), # latitude = c(30, 50), longitude = c(210, 240), # fields = 'x_wind' # ) p <- plotdap(crs = "+proj=robin") p <- add_griddap(p, murSST, ~analysed_sst) # p <- plotdap(mapTitle = "Average wind over time") # p <- add_griddap(p, QMwind, ~x_wind) # p <- plotdap("base", crs = "+proj=robin") # p <- add_griddap(p, murSST, ~analysed_sst) # layer tables on top of grids require(magrittr) p <- plotdap("base") %>% add_griddap(murSST, ~analysed_sst) %>% add_tabledap(sardines, ~subsample_count) # multiple time periods p <- plotdap("base", mapTitle = "Average wind over time") p <- add_griddap(p, QMwind, ~x_wind)
add_tabledap
adds the data from an 'rerddap::tabledap()' call to
a 'plotdap' map
add_tabledap( plot, table, var, color = c("#132B43", "#56B1F7"), size = 1.5, shape = 19, animate = FALSE, cumulative = FALSE, ... )
add_tabledap( plot, table, var, color = c("#132B43", "#56B1F7"), size = 1.5, shape = 19, animate = FALSE, cumulative = FALSE, ... )
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 |
size |
the size of the symbol. |
shape |
the shape of the symbol. For valid options, see the 'pch' values
section on points. |
animate |
whether to animate over the |
cumulative |
- if animation should be cumulative -default FALSE |
... |
arguments passed along to |
A plotdap object
# base plotting tends to be faster, # but is less extensible plotdap("base") # test datasets in data folder to meet execution timings # code given to extract the data sardines <- rerddap::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() p1 <- add_tabledap(p, sardines, ~subsample_count) p2 <- add_tabledap(p, sardines, ~log2(subsample_count)) # using base R plotting p <- plotdap("base") p <- add_tabledap(p, sardines, ~subsample_count) # robinson projection p <- plotdap(crs = "+proj=robin") p <- add_tabledap(p, sardines, ~subsample_count)
# base plotting tends to be faster, # but is less extensible plotdap("base") # test datasets in data folder to meet execution timings # code given to extract the data sardines <- rerddap::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() p1 <- add_tabledap(p, sardines, ~subsample_count) p2 <- add_tabledap(p, sardines, ~log2(subsample_count)) # using base R plotting p <- plotdap("base") p <- add_tabledap(p, sardines, ~subsample_count) # robinson projection p <- plotdap(crs = "+proj=robin") p <- add_tabledap(p, sardines, ~subsample_count)
bbox_set
changes the bounding box in an plotdap object.
Particularly needed if using gganimate::animate()
bbox_set(plotobj, xlim, ylim)
bbox_set(plotobj, xlim, ylim)
plotobj |
valid plotdap object |
xlim |
new x-values of the bounding box |
ylim |
new y-values of the bounding box |
a plotdap object
p <- plotdap() p <- add_tabledap(p, sardines, ~subsample_count) xlim = c(-125, -115) ylim <- c(30., 50.) p <- bbox_set(p, xlim, ylim)
p <- plotdap() p <- add_tabledap(p, sardines, ~subsample_count) xlim = c(-125, -115) ylim <- c(30., 50.) p <- bbox_set(p, xlim, ylim)
pre-Download of murSST in 'add_griddap()' example so that example can run within CRAN Time limits
murSST
murSST
An object of class griddap_nc
(inherits from nc
, data.frame
) with 0 rows and 2 columns.
obtained using the 'rerddap' command murSST <- griddap( 'jplMURSST41', latitude = c(22, 51), longitude = c(-140, -105), time = c('last', 'last'), fields = 'analysed_sst' )
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.
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", ... )
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", ... )
method |
the plotting method. Currently ggplot2 and base plotting are supported. |
mapData |
an object coercable to an sf object via |
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 |
mapTitle |
a title for the map. |
mapFill |
fill used for the map. |
mapColor |
color used to draw boundaries of the map. |
... |
arguments passed along to |
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 rerddap's visualization methods –
browseVignettes(package = "rerddap")
.
A plotdap object
Carson Sievert
tabledap()
, griddap()
# base plotting tends to be faster (especially for grids), # but is less extensible plotdap("base") plotdap() plotdap("base")
# base plotting tends to be faster (especially for grids), # but is less extensible plotdap("base") plotdap() plotdap("base")
Print a ggplot plotdap object
## S3 method for class 'ggplotdap' print(x, ...)
## S3 method for class 'ggplotdap' print(x, ...)
x |
a ggplotdap object |
... |
currently unused |
Print a plotdap object
## S3 method for class 'plotdap' print(x, ...)
## S3 method for class 'plotdap' print(x, ...)
x |
a plotdap object |
... |
currently unused |
pre-Download of QMwind in 'add_griddap()' example so that example can run within CRAN Time limits
QMwind
QMwind
An object of class griddap_nc
(inherits from nc
, data.frame
) with 0 rows and 2 columns.
obtained using the 'rerddap' command wind <- griddap('erdQMwindmday', time = c('2016-11-16', '2017-01-16'), latitude = c(30, 50), longitude = c(210, 240), fields = 'x_wind') )
pre-Download of sardine data in 'add_tabledap()' example so that example can run within CRAN Time limits
sardines
sardines
An object of class tabledap
(inherits from data.frame
) with 56 rows and 5 columns.
obtained using the 'rerddap' command sardines <- tabledap( 'FRDCPSTrawlLHHaulCatch', fields = c('latitude', 'longitude', 'time', ' scientific_name', 'subsample_count'), 'time>=2010-01-01', 'time<=2012-01-01', 'scientific_name="Sardinops sagax"') )