r - 如何在 R 中创建包含俄罗斯欧洲部分的欧洲 map ?

标签 r ggplot2

我想绘制荷美线乘客人数的数据。我与欧盟统计局创建了一个 shapefile,但不包括俄罗斯。问题是,我不想要一张包含整个俄罗斯的 map ,而只想要如下的欧洲部分。

enter image description here

是否有仅适用于俄罗斯“欧洲”部分的 shapefile?

数据集如下所示:

<表类=“s-表”> <标题> 区域 频率 ID <正文> 奥地利 7095 AT 白俄罗斯 1 BY 比利时 3 BE 克罗地亚 103 人力资源 捷克共和国 27 CZ 法国 3374 FR 德国 4132 DE 希腊 1 GR 匈牙利 20 HU 意大利 2 它 拉脱维亚 34 LV 立陶宛 183 LT 卢森堡 4 LU 荷兰 29123 NL 波兰 2409 PL 罗马尼亚 171 RO 俄罗斯 1469 RU 斯洛伐克 1 SK 瑞士 4 CH 乌克兰 60 英国

使用以下代码,我成功创建了一张欧洲 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'))

enter image description here

关于r - 如何在 R 中创建包含俄罗斯欧洲部分的欧洲 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75556807/

相关文章:

r - 使用 ggplots 或其他使用 R 的替代包修改极坐标图

r - 使用 R 中的 Rayshader 在高度 3D map 上添加颜色

r - 频率分布的中位数

r - 如何收集然后变异一个新列然后再次传播到宽格式

r - 在带有 ggplot2 的条形图旁边

r - 将字符串解析为更新 ggplot theme() 的参数

r - 在ggplot中设置日期时间的x轴限制

r - 在我自己的函数中使用 summarise_ 和 group_by_

r - 使用R语料库保留文档ID

json - 如何读取嵌套的 JSON 结构?