-1

我在运行county_choropleth地图生成功能时遇到问题。我的数据集基本上是我用来cbind绑定在一起的两个数据框。第一个数据集来自county.regions(所以我得到了正确的数据格式county_choropleth),第二个包含我的数据,这两个数据集完全按纽约的县排序。

这是数据框快照的链接:

数据框的图像

在 R 指令的指导下,我将我希望作为要在地图上显示的数据的相关列命名为“值”,然后输入以下代码来创建地图:

county_choropleth(big_data, state_zoom = "new york")

这会引发以下错误:

错误:长度(唯一(na.omit(choropleth.df$value)))<= 9 不是 TRUE

对于如何解决这个问题,有任何的建议吗?无法找到一个很好的解释来解释它试图用错误表达什么。谢谢!

4

1 回答 1

1

df 中的值列必须是数字。否则,假定它是一个字符或因子,如果列中唯一值的 # 大于 9,则例程退出。

https://github.com/trulia/choroplethr/blob/master/R/usa.R

 render_helper = function(choropleth.df, scale_name, theme)
{
  # maps with numeric values are mapped with a continuous scale
  if (is.numeric(choropleth.df$value))
  {
    ggplot(choropleth.df, aes(long, lat, group = group)) +
      geom_polygon(aes(fill = value), color = "dark grey", size = 0.2) + 
      self$get_scale() + 
      theme;
  } else { # assume character or factor
    stopifnot(length(unique(na.omit(choropleth.df$value))) <= 9) # brewer scale only goes up to 9

    ggplot(choropleth.df, aes(long, lat, group = group)) +
      geom_polygon(aes(fill = value), color = "dark grey", size = 0.2) + 
      self$get_scale() + 
      theme;
  }
},
于 2015-11-16T07:04:15.360 回答