首页 > 解决方案 > 数字(nrowz)错误:map()r中的“长度”参数无效

问题描述

我希望在地图上遮盖特定的县。
为了开始研究这个,我在这里使用了这个基本代码(在几篇没有提到错误的帖子中建议)。例如:[https://stackoverflow.com/questions/33129917/shading-counties-using-fips-code-在-r-map

library(maps)

library(dplyr)

data(county.fips)

## Set up fake df_pop_county data frame
df_pop_county <- data.frame(region=county.fips$fips)
df_pop_county$value <- county.fips$fips
y <- df_pop_county$value
df_pop_county$color <- gray(y / max(y))

## merge population data with county.fips to make sure color column is
## ordered correctly.
counties <- county.fips %>% left_join(df_pop_county, by=c('fips'='region'))
map("county", fill=TRUE, col=counties$color)

但是当我运行这个(或什至类似的 map() 相关代码)时,我得到:数字(nrowz)中的错误:map()中的无效“长度”参数
我感谢任何关于如何解决此错误的建议。

标签: rfips

解决方案


你的代码没有运行。如果你运行这个,你会得到同样的错误吗?

library(maps)
library(tidyr)
library(dplyr)

data(county.fips)

dat=separate(county.fips, polyname, sep= ",", into=c("state", "county"))
dat = dat %>% group_by(state) %>% mutate(grp=cur_group_id(), color=terrain.colors(49)[grp])
map("county", fill=TRUE, col=dat$color, boundary=FALSE)

在此处输入图像描述


推荐阅读