仅更改 R 中地图的一部分的大小
Change the size on only part of a map in 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 package (v2.0.0)
于 2021-04-19 创建
也许 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))
这是一个可重现的例子。我已经获得了美国和英国的地图。我的问题是如何在不改变同一地块上美国部分的大小的情况下将英国部分的大小加倍。谢谢
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 package (v2.0.0)
于 2021-04-19 创建也许 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))