Hi!
For a paper on paper publishing locations around the world, I need to create a map where those places are clearly indicated on the map. I would like it to be as pretty as possible since it's for a scientific publication.
So far I used "elevatr" package and I produced a nice topographic map. What I'm afraid with that one is that the focus is taken away from my subject: here's the code I used:
Version: Version 2023.03.1+446 (2023.03.1+446)
#libraries
libs <- c("elevatr", "terra", "tidyverse",
"sf", "giscoR", "marmap")
installed_libs <- libs %in% rownames(installed.packages())
if (any(installed_libs == F)) {
install.packages(libs[!installed_libs])
}
invisible(lapply(libs, library, character.only = T))
#1. GET WORLD MAP
crsLONGLAT <- "+proj=longlat +datum=WGS84 +no_defs"
get_sf <- function() {
world_sf <- giscoR::gisco_get_countries(
year = "2016",
epsg = "4326",
resolution = "10"
)
world_transformed <- st_transform(world_sf, crs = crsLONGLAT)
return(world_transformed)
}
world_transformed <- get_sf()
# 2. GET ELEVATION DATA
get_elevation_data <- function(world_elevation, world_elevation_df) {
world_elevation <- get_elev_raster(
locations = world_transformed,
z = 3,
clip = "locations")
world_elevation_df <- as.data.frame(world_elevation, xy = T) %>%
na.omit()
colnames(world_elevation_df)[3] <- "elevation"
return(world_elevation_df)
}
world_elevation_df <- get_elevation_data()
# 3. MAP
library(marmap)
get_elevation_map <- function(world_map) {
world_map <- ggplot() +
geom_tile(data = world_elevation_df,
aes(x = x, y = y, fill = elevation)) +
scale_fill_etopo() +
coord_sf(crs = crsLONGLAT)+
theme_minimal() +
theme(text = element_text(family = "georg", color = "#22211d"),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
legend.position = "none",
panel.grid.major = element_line(color = "white", size = 0.2),
panel.grid.minor = element_blank(),
plot.title = element_text(size=18, color="grey20", hjust=1, vjust=-5),
plot.caption = element_text(size=8, color="grey70", hjust=.15, vjust=20),
plot.margin = unit(c(t=0, r=0, b=0, l=0),"lines"), #added these narrower margins to enlarge maps
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA),
panel.border = element_blank()) +
labs(x = "",
y = NULL,
title = "Topographic map world",
subtitle = "",
caption = "CRD")
return(world_map)
}
world_map <- get_elevation_map()
#world_map
ggsave(filename="world_topo_map.png", width=7, height=8.5, dpi = 600, device='png', world_map)
I also used a simple map using ggplot. Here's the code I used:
world_coordinates <- map_data("world")
ggplot() + geom_map(
data = world_coordinates, map = world_coordinates,
aes(x = x, y = y, map_id = region),
color = "white", fill = "lightgray", size = 0.1 ) +
geom_point(
data = duse_cut,
aes(x, y, fill="#e672f4"), # dark blue
alpha = 0.7) +
theme_bw() +
theme(legend.position="none")
Any suggestion on a world map that I could use?