Here's a start point that you can add your geom_point
layer to. First, I load the libraries, which are numerous. marmap
and oce
are required for bathymetry and coastline data, respectively. RColorBrewer
is used for the colour palette for the bathymetry, while dplyr
is needed for mutate
. magrittr
provides the compound assignment pipe operator (%<>%
), tibble
is used when I restructure the bathymetry data, and ggthemes
provides theme_tufte
.
# Load libraries
library(ggplot2)
library(marmap)
library(oce)
library(RColorBrewer)
library(dplyr)
library(magrittr)
library(tibble)
library(ggthemes)
Here, I get the bathymetry data, restructure it, and bin it into depth intervals.
# Get bathymetry data
bathy <- getNOAA.bathy(lon1 = -68, lon2 = -56,
lat1 = 41, lat2 = 49,
resolution = 1, keep = TRUE)
bathy <- as.tibble(fortify.bathy(bathy))
bathy %<>% mutate(depth_bins = cut(z, breaks = c(Inf, 0, -200, -500, -1000,
-1500, -2000, -2500, -3000, -Inf)))
Next, I get the coastline data and put it into a data frame.
# Get coast line data
data(coastlineWorldFine, package = "ocedata")
coast <- as.data.frame(coastlineWorldFine@data)
Finally, I plot it.
# Plot figure
p <- ggplot()
p <- p + geom_raster(data = bathy, aes(x = x, y = y, fill = depth_bins), interpolate = TRUE, alpha = 0.75)
p <- p + geom_polygon(data = coast, aes(x = longitude, y = latitude))
p <- p + coord_cartesian(ylim = c(42, 47), xlim = c(-67, -57))
p <- p + theme_tufte()
p <- p + theme(axis.text = element_blank(),
axis.title = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
legend.position = "right",
plot.title = element_text(size = 24),
legend.title = element_text(size = 20),
legend.text = element_text(size = 18))
p <- p + scale_fill_manual(values = rev(c("white", brewer.pal(8, "Blues"))), guide = "none")
print(p)
This gives the following:
Adding a geom_point
layer would allow you to plot your field sites.
plot
withggplot2
geom_
s. You're mixing two very different plot composition and rendering engines together and that's just not going to work. – hrbrmstr