r - 数字(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()中的无效“长度”参数
我感谢任何关于如何解决此错误的建议。
解决方案
你的代码没有运行。如果你运行这个,你会得到同样的错误吗?
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)
推荐阅读
- kubernetes - 如果清单中未指定,pod 将使用什么 CPU 和内存?
- laravel - 为什么我无法将 Cron 条目添加到我的 ubuntu 18.04 服务器?
- javascript - 使用不同的参数将对象的方法绑定到另一个类的属性中
- c++ - __cxxabiv1::__class_type_info 和 __cxxabiv1::__si_class_type_info 错误与 STM32F4、C 和 C++ 结合
- c++ - 为什么 std::forward 有一个采用右值引用的重载?
- python - 如何在使用 pip 安装 Eel 时修复此错误
- java - 最新版本的 Memcached windows 二进制文件
- android - 如何在 android studio 中实现另一个 github 帐户的分叉回购?
- python - 为什么我不能在 heroku 上访问我的 django 网站
- powershell - 如何使用 powershell 脚本更改 Nlog.config 变量值