Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 按sf地图中单位的颜色组显示_R_Ggplot2_Dplyr_Sf - Fatal编程技术网

R 按sf地图中单位的颜色组显示

R 按sf地图中单位的颜色组显示,r,ggplot2,dplyr,sf,R,Ggplot2,Dplyr,Sf,我有一个技术问题要问你: 我有一份关于一个地区几个城市的档案 library(dplyr) library(ggplot2) library(sf) read_sf("cities.shp") %>% ggplot() + geom_sf() + theme_bw() 我的shp看起来是这样的: Code Name Long Lat Groups <chr> <chr> <dbl> &

我有一个技术问题要问你:

我有一份关于一个地区几个城市的档案

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
代码名长Lat组
134001阿贝…724751。62623339
2 34002 ADIS…734961。627068810
3 34003 AGDE 739245。62457287.
434004 AGEL 688135。62499054.
5 34005阿贡…758530。631134520
634006 AIGNE 683215。62470004.
7340007艾古…685638。62499764.
834008莱斯…705573。62744826.
934009 ALIG…727555。62632589
103401…747789。628751118
我想有一个城市地图,但也与城市分组(变量组)。因此,我所在的同一组城市将被其分组的一条线(例如红色)包围。我想显示我的城市和组。我还想知道,是否有可能用透明效果给这些群体涂上颜色,这样我们就可以看到下面社区的边界

谢谢

所以,很简单

像ohter
geom_x
code一样,我们可以使用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() )
(测试%变异(组=作为因子(组))%>%
突变(组=因子(组,水平=c(paste0(1:23)))%>%
ggplot()+geom_sf(aes(fill=Groups))+theme_bw()

就这些,谢谢

不知道你想要什么。请修改您的问题。您是否看过ggforce套装中的
geom_mark_*()
geom系列?我不知道这是否符合我的期望,因为我的团队边界是城市集会的外部边界。如果有人知道如何只增加我团队的轮廓,我很感兴趣!非常感谢。