knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE) library(quantarcticR) ## for vignette purposes, and if this is Ben's computer, use a persistent cache_dir if (grepl("ben_ray", qa_cache_dir())) qa_cache_dir("c:/data/Quantarctica3")
The quantarcticR
package provides access to Quantarctica data sets for R users, without needing QGIS to be installed.
This vignette:
Quantarctica is a collection of Antarctic geographical datasets which works with the free, cross-platform, open-source software QGIS. It includes community-contributed, peer-reviewed data from ten different scientific themes and a professionally-designed basemap.
Quantarctica is is published and made available under under a Creative Commons Attribution 4.0 International License.
If you use it, please cite it:
Matsuoka K, Skoglund A, Roth G (2018) Quantarctica dataset
. Norwegian Polar Institute. https://doi.org/10.21334/npolar.2018.8516e961
In addition, published works produced using Quantarctica are asked to cite each dataset that was used in the work. Please consult the abstract of each data set for the relevant citation.
The quantarcticR R package provides you with flexibility to either temporarily or persistently store the data that is downloaded from Quantarctica. By default a temporary directory is used, which will only persist for the current R session. This means that data will not be re-used from session to session, and you may end up re-downloading the same data if you run the same script in different sessions.
You can instead choose to save the data to a persistent directory, by issuing the command qa_cache_dir("persistent")
after loading the quantarcticR
package. This will use a standard user data directory (e.g. under the user's AppData
directory on Windows operating systems). You could also specify a particular directory to use, if you prefer:
qa_cache_dir("c:/my/data/directory/")
You can switch cache directories at any time, and you can find out the current cache directory by calling qa_cache_dir()
with no arguments.
Start by loading the package:
library(quantarcticR)
In order to return a list of the datasets available, use the qa_datasets
function.
datasets <- qa_datasets() head(datasets)
In the datasets
object we can see the following:
layername
which is the name of the datasetmain_file
is the primary data file associated with each datasettype
which is the object type (currently "shapefile" or "raster")cached
whether it has been downloaded to the local cache or notdownload_size
which is the size of the dataset.In order to view the details of a dataset use the qa_dataset
function. This function gives more information about the dataset (but does not download or return the actual data). For example, with the simple basemap called "ADD Simple basemap":
basemap <- qa_dataset("ADD Simple basemap") basemap
To actually fetch the data, use the qa_get
function. You can provide it with either the name of the dataset (i.e. layername
as returned by qa_datasets()
) or the dataset object (as returned by qa_dataset()
).
Here we'll fetch a dataset called "AntGG Free-air gravity anomaly (10km)".
ga_info <- qa_dataset("AntGG Free-air gravity anomaly (10km)") ## the dataset info ga_data <- qa_get(ga_info, verbose = TRUE) ## fetch the actual data class(ga_data)
The gravity anomaly data set is a raster, so we can use the raster package to plot it.
library(raster) plot(ga_data)
The Quantarctica project maintainers have gone to quite a lot of effort to create nice visual representations of the data layers, by defining colour palettes and similar. The full range of visual information is not yet available through quantarcticR, but it is a work in progress. In this case, there is a colour palette for the gravity anomaly layer:
cmap <- ga_info$palette[[1]] cmap
We need to make some tweaks to the palette to cope with the differences in how QGIS defines them compared to how raster
expects them (we will endeavour to automatically deal with such differences in future versions of quantarcticR):
breaks <- c(cmap$value, cellStats(ga_data, "max")) breaks[1] <- cellStats(ga_data, "min")
Re-plot using that colour map, and with a land layer underneath:
basemap <- qa_get("ADD Simple basemap") plot(basemap) plot(ga_data, breaks = breaks, col = cmap$color, add = TRUE, legend = FALSE)
which is a little closer to the Quantarctica-rendered version of the same data layer:
Read in the simple basemap "ADD Simple basemap" data as an sf object and use the ggplot2 and sf packages to create a plot.
library(sf) library(ggplot2) surface_sf <- qa_get("ADD Simple basemap", shapefile_reader = sf::st_read) class(surface_sf) ggplot(surface_sf) + geom_sf()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.