Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
混淆geom_地图错误choropleth_R_Ggplot2_Choropleth - Fatal编程技术网

混淆geom_地图错误choropleth

混淆geom_地图错误choropleth,r,ggplot2,choropleth,R,Ggplot2,Choropleth,我在使用geom_map时遇到了一个错误,在尝试制作choropleth贴图时,我在使用geom_polygon时没有遇到这个错误 我正在尽可能密切地关注这个问题 我有一个位置的data.frame和一个id列(lease\u number),供以后参考: dfmap<- read.table(text="id long lat order hole piece group lease_number 1 -90.38103 28.78907

我在使用
geom_map
时遇到了一个错误,在尝试制作choropleth贴图时,我在使用
geom_polygon
时没有遇到这个错误

我正在尽可能密切地关注这个问题

我有一个位置的data.frame和一个id列(
lease\u number
),供以后参考:

dfmap<- read.table(text="id      long      lat order  hole piece group lease_number
             1 -90.38103 28.78907     1 FALSE     1   1.1        00016
             1 -90.38065 28.82965     2 FALSE     1   1.1        A0016
             1 -90.33457 28.82930     3 FALSE     1   1.1        A0016
             1 -90.33497 28.78872     4 FALSE     1   1.1        A0016
             1 -90.38103 28.78907     5 FALSE     1   1.1        A0016", header=T)
给出以下错误:

Error in unit(x, default.units) : 'x' and 'units' must have length > 0
通过像这样合并数据,我可以生成正确的绘图

ggplot() +
  geom_polygon(data=merge(dfmap, df, by='lease_number', all=T),
               aes(x=long, y=lat, group=lease_number, fill=var1))
但是我想避免这种情况,因为我需要引用很多不同的东西,并且能够在两个data.frames之间引用
lease\u number
列会更好

我已经看到了,但是这个答案不适用于这里,因为如果我删除
fill=
参数,我甚至无法获得一个底图来显示
geom\u map
。有人知道如何面对这个错误吗


谢谢。

在紧跟文档中的第二个示例之后,我将dfmap中的变量名从“lease\u number”更改为“region”,但在df中将其保留为“lease\u number”。这似乎给了你想要的结果,但我不知道为什么。(您还需要更改如何使用
expand_limits
,以便与第二个示例类似)。在紧跟文档中的第二个示例之后,我将dfmap中的变量名从“lease_number”更改为“region”,但在df中保留为“lease_number”。这似乎给了你想要的结果,但我不知道为什么。(您还需要更改如何使用
expand\u limits
,以便与第二个示例类似)。
Error in unit(x, default.units) : 'x' and 'units' must have length > 0
ggplot() +
  geom_polygon(data=merge(dfmap, df, by='lease_number', all=T),
               aes(x=long, y=lat, group=lease_number, fill=var1))