Robert Schlegel
ggOceanMaps
provides the full suite of solutions# Load libraries
library(tidyverse)
library(ggOceanMaps)
library(ggOceanMapsData)
# NB: ggOceanMapsData is not on CRAN
# Uncomment and run this line of code:
# remotes::install_github("MikkoVihtakari/ggOceanMapsData")
# If this causes an error, think about why
# Fixed base map
map_global_fix <- map_data('world') %>%
rename(lon = long) %>%
mutate(group = ifelse(lon > 180, group+2000, group),
lon = ifelse(lon > 180, lon-360, lon))
# Load SST from 2022-12-25 to 2022-12-31
load("../data/OISST_2022.RData")
No matter what you’ve heard, its not flat. Proof of this is that if it were flat, it would be much easier to plot parts of it on a map! Instead, because the surface of the Earth is curved, we cannot accurately plot it on a computer screen.
The way we deal with this is by changing the measurements between longitude/latitude coordinates. The technical word is ‘projecting’. The noun is ‘projection’ or ‘projections’.
For much of the Earth this is not that noticeable. But for the Arctic it is a big issue.
There are many different sorts of map projections in use. Over tea time I recommend googling them. There are some interesting ones.
The Spilhaus projection is oriented around the global ocean.
R has many built-in projections, and ggplot2
gives us easy access to many of them.
crs
map projections with the _sf()
range of functionscrs
= Coordinate Reference Systemsf
and stars
coord_polar()
does not quite give us what we wantcoord_map()
# Filter map data and plot it in one code chunk
map_global_fix %>%
filter(lon > 9, lon < 28, lat > 76, lat < 81) %>%
ggplot(aes(x = lon, y = lat)) +
geom_polygon(aes(group = group)) +
# Filtering the OISST_2022 data directly in geom_tile()
geom_tile(data = filter(OISST_2022,
lon > 9, lon < 28, lat > 76, lat < 81),
aes(fill = temp)) +
coord_map(projection = "ortho", orientation = c(90, 0, 0))
# Filter map data and plot it in one code chunk
map_global_fix %>%
filter(lon > 9, lon < 28, lat > 76, lat < 81) %>%
ggplot(aes(x = lon, y = lat)) +
geom_polygon(aes(group = group)) +
# Filtering the OISST_2022 data directly in geom_tile()
geom_tile(data = filter(OISST_2022,
lon > 9, lon < 28, lat > 76, lat < 81),
aes(fill = temp)) +
coord_cartesian(expand = F)
ggOceanMaps
ggOceanMaps
ggOceanMaps
ggOceanMaps
To cite package 'ggOceanMaps' in publications use:
Vihtakari M (2022). _ggOceanMaps: Plot Data on Oceanographic Maps
using 'ggplot2'_. R package version 1.3.4,
<https://CRAN.R-project.org/package=ggOceanMaps>.
A BibTeX entry for LaTeX users is
@Manual{,
title = {ggOceanMaps: Plot Data on Oceanographic Maps using 'ggplot2'},
author = {Mikko Vihtakari},
year = {2022},
note = {R package version 1.3.4},
url = {https://CRAN.R-project.org/package=ggOceanMaps},
}