I would like to remove the white background that is created around the world map when plotting in Mollweide projection using theme_bw()
as a base, in R. This is my code:
library(pacman)
p_load(terra, ggspatial, ggthemes, sf, tidyverse, viridis, cowplot)
# load world map
wrld <- ne_countries()
# reproject to mollweide
wrld_moll <- project(terra::vect(wrld), "+proj=moll +lon_0=0 +x_0=0 +y_0=0")
# transform as sf
wlrd_sf <- st_as_sf(wrld_moll)
# plot
p1 <- ggplot() +
# add world as a background
geom_sf(data = wlrd_sf, fill = "grey90", col = "grey60", linewidth = 0.25) +
# add theme map
theme_bw() +
# personalize theme
theme(axis.title = element_blank(),
panel.border = element_rect(fill = NA,
colour = "#238B45",
linewidth = 2,
inherit.blank = T))
p1
Which gives this map (I pasted the map on a blue background to show the difference with the next one):
I try to remove the background by adding these lines to my personalized theme:
p2 <- p1 + theme(axis.title = element_blank(),
plot.background = element_rect(fill = "transparent",
colour = NA_character_), # necessary to avoid drawing plot outline
panel.background = element_rect(fill = "transparent",
colour = NA_character_), # necessary to avoid drawing panel outline
panel.border = element_rect(fill = NA,
colour = "#238B45",
linewidth = 2,
inherit.blank = T))
Which removes also the background of the world (eg seas, oceans), not only the background between the world and the panel:
What I would like is those areas between the world map and the panel border (where I have put a blue big dot) to be transparent, but keeping oceans and seas white.
I think it is some theme_bw()
setting but so far I cannot find/change it.