How do you download and style bathymetry data in R? One way is using the marmap library. This script will:
- Download bathymetry data from NOAA
- Create a palette of reversed, blue colours
- Create a simple plot
- Save the plot to a PNG file
# Load libraries
library(marmap)
library(RColorBrewer)
# Set working directory
setwd("C:\\R\\")
# Download bathymetry data from NOAA
caribbean <- getNOAA.bathy(lon1 = -90, lon2 = -58,
lat1 = 6, lat2 = 24,
resolution = 3,
keep = TRUE) # Save downloaded data to working directory
# Create a palette of blues using a reversed palette from RColorBrewer
blues <- rev(brewer.pal(4, "Blues"))
# Open a PNG file for saving the plot
png("Caribbean.png", width = 800, height = 600)
# Plot the bathymetry
plot(caribbean, image = TRUE,
land = TRUE,
lwd = 0.1,
bpal = list(c(0, max(caribbean), "grey"),
c(min(caribbean),0,blues)))
# Close the PNG file
dev.off()
More on marmap here.