r - 在 R 中仅更改部分地图的大小
问题描述
这是一个可重现的例子。我已经获得了美国和英国的地图。我的问题是如何在不改变同一地块上美国部分的大小的情况下将英国部分的大小增加一倍。谢谢。
library(tidyverse)
library(rnaturalearth)
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(ggthemes)
map_uk<- st_as_sf(ne_countries(country = 'united kingdom' ,
type = 'map_units')) %>%
select(country = admin, name, geometry)
map_us <- st_as_sf(ne_states(country = "united states of america"
)) %>%
select(country = admin, name, geometry) %>%
filter(!name %in% c("Alaska", "Hawaii"))
map_both <- map_uk %>% rbind(map_us)
map_both %>%
ggplot()+
geom_sf(aes(geometry = geometry, fill = name)) +
theme_map() +
theme(legend.position = "none")
由reprex 包于 2021-04-19 创建 (v2.0.0 )
解决方案
也许与cowplot
:
这是我的尝试:
library(tidyverse)
library(rnaturalearth)
library(sf)
library(ggthemes)
library(cowplot)
map_uk<- st_as_sf(ne_countries(country = 'united kingdom' ,
type = 'map_units')) %>%
select(country = admin, name, geometry)
map_us <- st_as_sf(ne_states(country = "united states of america")) %>%
select(country = admin, name, geometry) %>%
filter(!name %in% c("Alaska", "Hawaii"))
US <- ggplot(data=map_us) +
geom_sf() +
theme_map()
UK <- ggplot(data=map_uk) +
geom_sf() +
theme_map()
ggdraw() + draw_plot(US, x=0,y=0,width = 0.75, height = 0.8) + draw_plot(UK, x=0.65,y=0.4,width = 0.45, height = 0.4)
第二次尝试
map_both <- map_uk %>% rbind(map_us)
both <- map_both %>%
ggplot()+
geom_sf(aes(geometry = geometry, fill = name)) +
theme_map() +
theme(legend.position = "none")
UK2 <- both %+% subset(map_both,country %in% c("United Kingdom"))
US2 <- both %+% subset(map_both,country %in% c("United States of America"))
plot_grid(US2,UK2,ncol=2, scale=c(1,0.4))
推荐阅读
- visual-studio-code - 无法在 vscode 中打开已保存的工作区
- java - android.database.sqlite.SQLiteException:表contacts_table没有名为phone_number的列(代码1):,编译时:INSERT INTO contacts_table
- javascript - 如何在 React Native 中返回一个值的一行中获取 Firebase Cloud Firestore 数据
- javascript - 使用 JQuery 的动画滚动
- python - 将两个文件与第三个文件的输入进行比较,并将最大计数写入第四个文件
- asp.net - 浏览到 WIndows 2012 网站时出现 F12 控制台窗口 JavaScript 浏览器错误
- go - 在 Golang 中合并两个文本文件
- vue.js - 未知突变类型:isOpen/toggleSideBar [vuex]
- ios - 我无法向我的应用发送 Firebase Cloud Messaging 推送通知我按照这些步骤操作但无处可去
- android - AppCenter:如何在 Xamarin 中检索“notification_content”对象的“name”属性?