1 | initial version |
To merge maps of land without water and contour plots and remove the ocean areas, you can follow these steps:
library(ggplot2)
library(maptools)
library(raster)
land <- readShapePoly("land.shp")
contours <- raster("elevation.tif")
contours.df <- fortify(contours)
merged.df <- merge(land, contours.df, by = "id")
ggplot(merged.df) +
geom_polygon(aes(x = long, y = lat, group = group, fill = value)) +
coord_equal() +
theme_void()
To obscure the ocean areas, you can add a layer with a polygon that covers the entire plot area with a color that matches your plot background. For example:
ggplot(merged.df) +
geom_polygon(aes(x = long, y = lat, group = group, fill = value)) +
coord_equal() +
theme_void() +
geom_polygon(data = world, aes(long, lat, group = group), fill = "white")
To fill in the ocean areas with a color, you can use the ggrepel package to create a layer with text labels that cover the ocean areas, and set the text color to match your plot background. For example:
library(ggrepel)
ggplot(merged.df) +
geom_polygon(aes(x = long, y = lat, group = group, fill = value)) +
coord_equal() +
theme_void() +
geom_text_repel(data = world, aes(long, lat, label = " "), size = 10, color = "white")