我想绘制荷美线乘客人数的数据。我与欧盟统计局创建了一个 shapefile,但不包括俄罗斯。问题是,我不想要一张包含整个俄罗斯的 map ,而只想要如下的欧洲部分。
是否有仅适用于俄罗斯“欧洲”部分的 shapefile?
数据集如下所示:
使用以下代码,我成功创建了一张欧洲 map (不包括俄罗斯)。但是,是否有可能获得俄罗斯欧洲部分的几何形状?
# Get geometrics
Europe_shp <- get_eurostat_geospatial(resolution = 10,
nuts_level = 0,
year = 2016)
# Merge passenger data data with geometrics
European_Countries_1907 <- merge(country_passengers_1907_europe_code, Europe_shp, all.x = TRUE, all.y = TRUE, by.x = "ID", by.y = "id")
# Create plot of Europe
vector_colors_gradient_2 <- c("#fff997", "#ffd983", "#ffb97b", "#f89b79","#e6807c", "#cd6a80", "#ad5983", "#874c82", "#5d427b", "#2b386f")
Map_1907 <- European_Countries_1907 %>%
ggplot(aes(fill = log10(Freq))) +
aes(geometry = geometry) +
geom_sf(size = 0.1, color = "#F3F3F3") +
scale_fill_gradientn(colours = vector_colors_gradient_2,
labels = ~scales::comma(10^.x)) +
scale_x_continuous(limits = c(-10, 27)) +
scale_y_continuous(limits = c(33, 70)) +
labs(
title = "Travellers from Europe",
subtitle = "Number of HAL Passengers in 1907",
caption = "Data: Stadsarchief Rotterdam",
fill = "Number of Passengers"
) +
theme_void() +
theme(plot.margin = margin(20, 0, 20, 20))
Map_1907
最佳答案
正如 tjebo 所说,rnaturalearth 软件包是地理数据的重要来源。您可以将整个世界作为 shapefile 并使用您自己的数据执行左连接。复制上面的 map 需要将 crs 设置为 EPSG 3035 和适当的轴限制进行绘图:
library(rnaturalearth)
library(sf)
library(ggplot2)
world <- ne_countries(scale = 50, returnclass = 'sf')
ggplot(world) +
geom_sf(aes(fill = continent), color = 'black') +
geom_sf_text(aes(label = name), size = 5) +
coord_sf(crs = st_crs(3035),
xlim = c(2000000, 6200000),
ylim = c(1500000, 5500000)) +
scale_fill_manual(values = c('#c4c0a0', NA, '#c9cc3d', '#fcd752',
NA, NA, NA, NA), guide = 'none',
na.value = 'white') +
theme(panel.background = element_rect(fill = '#92c5f0'),
panel.grid.major = element_line(linewidth = 0.1,
color = '#80808080'))
关于r - 如何在 R 中创建包含俄罗斯欧洲部分的欧洲 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75556807/