Robert Schlegel
library(tidyverse)
The rOpenSci project is a massive international effort to create free open source tools to access, analyse, and visualise a very wide range of scientific data. Thanks to this project there are more and more new packages every month that allow us to more easily access the datasets etc. we may be interested in. Many of the packages we will look at today come from this source. It also contains many more useful packages not shown in these slides. Use the search bar on this page to find what you are looking for.
ggplot2
ggplot2
# The library containing these functions
library(pangaear)
# Search for PAR data within Kongsfjorden
# NB: Bounding box is: minlon, minlat, maxlon, maxlat
search_res <- pg_search(query = "PAR", bbox = c(11, 78, 13, 80), count = 10)
head(search_res)
# A tibble: 6 × 6
score doi size size_measure citation suppl…¹
<dbl> <chr> <dbl> <chr> <chr> <chr>
1 27.6 10.1594/PANGAEA.945341 118290 data points Bartsch, I; Paar, M;… <NA>
2 24.9 10.1594/PANGAEA.918047 3 datasets Voß, D; Wollschläger… <NA>
3 23.5 10.1594/PANGAEA.917534 3 datasets Friedrichs, A; Schwa… <NA>
4 17.8 10.1594/PANGAEA.935688 498 datasets Nicolaus, M; Anhaus,… <NA>
5 13.8 10.1594/PANGAEA.902056 19 datasets Castellani, G; Flore… <NA>
6 13.5 10.1594/PANGAEA.894853 96 data points Springer, K; Lütz, C… Spring…
# … with abbreviated variable name ¹supplement_to
# Download
kong_PAR_dl <- pg_data(doi = search_res$doi[1])
# Prep
kong_PAR <- kong_PAR_dl[[1]]$data %>%
mutate(t = as.POSIXct(str_replace(`Date/Time`, "T", " ")))
# Plot
kong_PAR %>%
filter(t < "2012-07-31 00:00:00") %>%
ggplot(aes(x = t, y = `PAR [µmol/m**2/s]`)) +
geom_line(aes(colour = as.factor(`Depth water [m]`))) +
facet_wrap(~Comment, ncol = 1) +
labs(x = NULL, colour = "Depth [m]",
title = "PAR data from Kongsfjorden for July, 2012",
subtitle = "Shallower values taken both above and below kelp canopy",
caption = str_wrap(kong_PAR_dl[[1]]$citation, 100))
This is not one single source, rather this is a sort of technology that has been developed to allow us to subet data from online databases. For our applications, this generally means we are extracting spatial subsets of physical/chemical data from gridded datasets. The following slides provide some examples of how this works.
# First we start with the dataset name
OISST_dl <- griddap(datasetx = "ncdcOisst21Agg_LonPM180",
# Then we provide the site where the data are
url = "https://coastwatch.pfeg.noaa.gov/erddap/",
# The range of dates we want
time = c("2020-12-25", "2020-12-31"),
# The depth range
zlev = c(0, 0),
# lon/lat are taken from the centre of the pixel
longitude = c(-179.875, 179.875),
latitude = c(-89.875, 89.875),
# Then list the data layer you want
# These can be found on the dataset website
fields = "sst")
# Filter for quicker plotting
OISST_2020 %>%
filter(lon > 6, lon < 32, lat > 76, lat < 81,
t != "2020-12-28") %>%
ggplot() + borders() +
geom_raster(aes(x = lon, y = lat, fill = temp)) +
scale_fill_viridis_c() +
coord_quickmap(xlim = c(6, 32), ylim = c(76, 81), expand = F) +
facet_wrap(~t) + labs(x = NULL, y = NULL)