创建地图时,R中的County_Choropleth出现错误

创建地图时,R中的County_Choropleth出现错误,r,choropleth,R,Choropleth,运行country\u choroplethmap生成函数时出现问题。我的数据集基本上是两个数据帧,我使用cbind将它们绑定在一起。第一个数据集来自country.regions(因此我获得了country\u choropleth)的数据格式,第二个包含了我的数据,这两个数据集完全按照纽约的县进行排序 以下是指向数据帧快照的链接: 按照R指令的指导,我将要在地图上显示的数据的相关列命名为“值”,然后输入以下代码来创建地图: county_choropleth(big_data, state

运行
country\u choropleth
map生成函数时出现问题。我的数据集基本上是两个数据帧,我使用
cbind
将它们绑定在一起。第一个数据集来自
country.regions
(因此我获得了
country\u choropleth
)的数据格式,第二个包含了我的数据,这两个数据集完全按照纽约的县进行排序

以下是指向数据帧快照的链接:

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

county_choropleth(big_data, state_zoom = "new york")
这会引发以下错误:

错误:长度(唯一(na.omit(choropleth.df$value))
df中的值列必须是数字。否则,假定它是一个字符或因子,如果列中唯一值的#大于9,则例程将退出

render\u helper=函数(choropleth.df,scale\u名称,主题)
{
#具有数值的贴图以连续比例进行贴图
if(是数字的(choropleth.df$value))
{
ggplot(choropleth.df,aes(长、宽、组=组))+
几何多边形(aes(填充=值),颜色=“深灰色”,大小=0.2)+
self$get_scale()+
主题
}否则{#假设性质或因素

stopifnot(长度(唯一(na.omit(choropleth.df$value)))要添加到此答案,您可以通过
big\u data$value图片不是代码/数据将值列转换为数字。请在将来努力
dput()
数据。
 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;
  }
},