ggplot sf_geom 在多个区域之间创建自定义边框
ggplot sf_geom create custom border between multiple area
我想像这个答案一样在我的地图的多个子部分之间创建边界:
但是,它在我的 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()
因此,就我而言,我想在看到城市边界的同时在我的地图上绘制 "Groups" 边界(并保留 fill = Groups
颜色)。
原版post编辑了解决方案:
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()
我想像这个答案一样在我的地图的多个子部分之间创建边界:
但是,它在我的 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()
因此,就我而言,我想在看到城市边界的同时在我的地图上绘制 "Groups" 边界(并保留 fill = Groups
颜色)。
原版post编辑了解决方案:
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()