Ask Your Question

What is the method for concealing the ocean when creating a globe plot with ggplot in R, while displaying the plotted values?

asked 2022-11-01 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-28 10:00:00 +0000

nofretete gravatar image

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:


# 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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2022-11-01 11:00:00 +0000

Seen: 7 times

Last updated: Nov 28 '21