在底图上叠加 geofacet
Overlay geofacet on basemap
我正在尝试绘制一个简单的欧盟多面图,但覆盖了欧盟的底图。我只是想知道是否有可能做到这一点?
现在,我的代码如下,生成以下内容:
mydf %>%
ggplot(aes(x = x, y = y, group = name)) +
geom_line() +
coord_polar() +
facet_geo(~country, grid = "eu_grid1")
我可以使用以下方法轻松制作欧洲地图:
world <- map_data("world")
world %>%
filter(region %in% eu_grid1$name) -> europe
ggplot() +
geom_polygon(data=europe, aes(x=long, y=lat, group=group), color="black", fill="white")
但无法弄清楚如何同步(如果可能)和分层它们。谢谢!
是的,这是可能的。我不确定它在视觉上的效果如何。显然我没有你的数据,但我将使用来自 geofacet
的内置数据集来演示。
library(geofacet)
library(grid)
library(tidyverse)
facets <- eu_gdp %>%
ggplot(aes(x = year, y = gdp_pc)) +
geom_line() +
facet_geo(~name, grid = "eu_grid1") +
theme(plot.background = element_blank())
map_data("world") %>%
filter(region %in% eu_grid1$name) %>%
ggplot() +
geom_polygon(aes(x=long, y=lat, group=group),
color="black", fill="white") +
theme_void()
print(facets, newpage = FALSE)
由 reprex package (v2.0.1)
于 2022-03-09 创建
我正在尝试绘制一个简单的欧盟多面图,但覆盖了欧盟的底图。我只是想知道是否有可能做到这一点?
现在,我的代码如下,生成以下内容:
mydf %>%
ggplot(aes(x = x, y = y, group = name)) +
geom_line() +
coord_polar() +
facet_geo(~country, grid = "eu_grid1")
我可以使用以下方法轻松制作欧洲地图:
world <- map_data("world")
world %>%
filter(region %in% eu_grid1$name) -> europe
ggplot() +
geom_polygon(data=europe, aes(x=long, y=lat, group=group), color="black", fill="white")
但无法弄清楚如何同步(如果可能)和分层它们。谢谢!
是的,这是可能的。我不确定它在视觉上的效果如何。显然我没有你的数据,但我将使用来自 geofacet
的内置数据集来演示。
library(geofacet)
library(grid)
library(tidyverse)
facets <- eu_gdp %>%
ggplot(aes(x = year, y = gdp_pc)) +
geom_line() +
facet_geo(~name, grid = "eu_grid1") +
theme(plot.background = element_blank())
map_data("world") %>%
filter(region %in% eu_grid1$name) %>%
ggplot() +
geom_polygon(aes(x=long, y=lat, group=group),
color="black", fill="white") +
theme_void()
print(facets, newpage = FALSE)
由 reprex package (v2.0.1)
于 2022-03-09 创建