Create a map with bathymetry information in R.
Bathymetry gives us information on the water depth around an area.
This post includes:
- Download raster data
- Read and subset raster data
- Plot raster data
GEBCO: General Bathymetry Chart of the Oceans provides information from bathymetry in the ocean.
To download visit webpage
Go to:
- Download data for user-defined areas
- Use the application
- Add your coordinates -here I use 1 to 10 and 50 to 60-
- Add to basket and download
Once you had download the information, give the direction of the file. For example:
Load the terra package for reading raster data
The function rast helps to read raster data - replacing package raster
Bath_file<-rast(this_file)
Change to data frame
Bath_dataframe <- as.data.frame(Bath_file, xy = TRUE)
Alternatively, use the test information included in the package GermanNorthSea
##devtools::install_github("MiriamLL/GermanNorthSea")
library(GermanNorthSea)
Bath_dataframe<-GermanNorthSea::German_bath
Load the package tidyverse
Use filter to subset your data
Load the package ggplot2
Plot your data using geom_raster
ggplot() +
geom_raster(data = Bath_dataframe_sub , aes(x = x, y = y, fill = Bathymetry)) +
scale_fill_viridis_c(option = "mako")+
theme_void()+
theme(legend.position='bottom')+
xlab('Longitude')+ylab('Latitude')+
coord_sf(xlim = c(3,9), ylim = c(53,56),
label_axes = list(top = "E", left = "N", bottom = 'E', right='N'))
Load the package sf
Use the function st_transform to convert to the same CRS
German_land<-st_transform(GermanNorthSea::German_land, 4326)
Add the land to the plot using geom_sf
Plot_bath<-ggplot() +
geom_raster(data = Bath_dataframe_sub , aes(x = x, y = y, fill = Bathymetry)) +
geom_sf(data = German_land, colour = 'black', fill = '#ffffbe')+
scale_fill_viridis_c(option = "mako")+
theme_void()+
theme(legend.position='bottom')+
xlab('Longitude')+ylab('Latitude')+
coord_sf(xlim = c(3,9), ylim = c(53,56),
label_axes = list(top = "E", left = "N", bottom = 'E', right='N'))
Plot_bath
More details about how to add features to a map here