在 sf 地图中按单位颜色组显示
Display by color groups of units in sf map
我有技术问题要问你:
我有一个地区几个城市的 shapfile
library(dplyr)
library(ggplot2)
library(sf)
read_sf("cities.shp") %>%
ggplot() + geom_sf() + theme_bw()
我的 shp 看起来像这样:
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
我想要一张包含城市的地图,还有城市分组(可变组)。因此,同一组的我的城市将被其分组的一条线(例如红色)包围。我想展示我的城市并展示我的团体。我也想知道是否可以用透明效果给组上色,这样我们就可以看到下面的公社边界。
谢谢
所以,很简单...
像其他 geom_x
代码一样,我们可以使用 arg fill =
(test <- 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() )
就这些了,谢谢!
我有技术问题要问你:
我有一个地区几个城市的 shapfile
library(dplyr)
library(ggplot2)
library(sf)
read_sf("cities.shp") %>%
ggplot() + geom_sf() + theme_bw()
我的 shp 看起来像这样:
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
我想要一张包含城市的地图,还有城市分组(可变组)。因此,同一组的我的城市将被其分组的一条线(例如红色)包围。我想展示我的城市并展示我的团体。我也想知道是否可以用透明效果给组上色,这样我们就可以看到下面的公社边界。
谢谢
所以,很简单...
像其他 geom_x
代码一样,我们可以使用 arg fill =
(test <- 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() )
就这些了,谢谢!