r - ggplot sf_geom 在多个区域之间创建自定义边框
问题描述
我想在我的地图的多个子部分之间创建边界,如下所示:
https://stackoverflow.com/a/49523256/9829458
但是,它在我的 R 中不起作用。只绘制了这张地图的外部边框。当我在我的数据集上使用此代码时,我遇到了同样的问题......
我的数据:
city_code Name Long Lat Groups
<chr> <chr> <dbl> <dbl> <dbl>
1 34001 ABEI… 724751. 6262333. 9
2 34002 ADIS… 734961. 6270688. 10
3 34003 AGDE 739245. 6245728. 7
4 34004 AGEL 688135. 6249905. 4
5 34005 AGON… 758530. 6311345. 20
6 34006 AIGNE 683215. 6247000. 4
7 34007 AIGU… 685638. 6249976. 4
8 34008 LES … 705573. 6274482. 6
9 34009 ALIG… 727555. 6263258. 9
10 34010 ANIA… 747789. 6287511. 18
我的地图:
read_sf("Map.shp") %>%
mutate(Groups = as.factor(Groups)) %>%
mutate(Groups = factor(Groups, levels = c(paste0(1:23)))) %>%
ggplot() +
geom_sf(aes(fill = Groups)) +
theme_bw()
所以,就我而言,我想在我的地图上绘制“组”边界,同时看到城市边界(并保存fill = Groups
颜色)。
解决方案
解决方案在原始帖子中进行了编辑:
read_sf("Map.shp") %>%
mutate(Groups = as.factor(Groups)) %>%
mutate(Groups = factor(Groups, levels = c(paste0(1:23)))) %>%
ggplot() +
geom_sf(aes(fill = Groups), size = 0.4) +
geom_sf(fill = "transparent", color = "Black", size = 1, data = . %>% group_by(Groups) %>% summarise()) +
theme_bw()
推荐阅读
- python - Python 等价于 Java Exception with cause
- php - 使用 AJAX 在 HTML 页面中获取 XML 数据
- powerbi - Power BI 在同一行显示标题和值
- python - 试图理解使用 inplace = true vs false 更改列名
- c++ - 使用c ++连续将数据从服务器发送到接收器
- python - 使用 matplotlib/seaborn 从 pivot_table 绘制 sub_plots
- spring - 在 Spring 执行器中:HealthEndPoint.health() 是否给出与调用 /health 端点相同的结果?
- java - 解析时获取 com.fasterxml.jackson.core.JsonParseException
- jenkins - 在 Jenkins 的 JMeter 负载测试期间获取服务器的 CPU 和内存使用情况图
- css - Css 网格重复语法