One method for concealing the ocean when creating a globe plot with ggplot in R while displaying the plotted values is to use the map_data()
function from the ggplot2
package to obtain a dataset of landmasses only. This can be done by specifying the region
argument in map_data()
to a specific continent, such as region = "world"
or region = "north america"
.
Once the landmass data is obtained, it can be used to create a polygon layer in ggplot that only displays land areas. For example:
library(ggplot2)
# Get data for landmasses only
world <- map_data("world")
# Create ggplot with only land areas
ggplot() +
theme_void() +
geom_polygon(data = world,
aes(x = long, y = lat, group = group),
fill = "gray80")
This will create a blank gray globe with only landmasses displayed, which can then be overlaid with the desired plot data.
Asked: 2022-11-01 11:00:00 +0000
Seen: 7 times
Last updated: Nov 28 '21