我有两个类型为 Large SpatialPointsDataFrame 的对象,名为 st2 和 st10 .它们来自同一个来源。他们都没有问题的情节:
plot(st2)
或者
plot(st10)
但我想用 ggmap 和 ggplot 绘制它们。我可以为 执行此操作st2 用这样的简单代码:
map <- get_map(location = 'Poznań', zoom = 12)
ggmap(map) + geom_point(aes(x =st2@coords[,1], y = st2@coords[,2]))
但是说到 st10 我收到一个错误:
Error in data.frame(x = c(16.910848618, 16.910863876, 16.910913467, 16.910936356, :
arguments imply differing number of rows: 53885, 4
我用长度()检查值:
> length(st10@coords[,1])
[1] 53885
> length(st10@coords[,2])
[1] 53885
我用 summary() 检查它们
> summary(st10@coords[,1])
Min. 1st Qu. Median Mean 3rd Qu. Max.
16.84 16.88 16.91 16.91 16.91 16.99
> summary(st10@coords[,2])
Min. 1st Qu. Median Mean 3rd Qu. Max.
52.35 52.41 52.46 52.44 52.46 52.46
怎么了?我有超过 20 个这样的 SP 数据框和一些情节以及其他给出了上面提到的错误......这与点数无关
有什么问题?或者也许有人可以给我一些提示,我该如何调试?
最佳答案
我通过制作一个新的数据框来解决这个问题。
tlData=data.frame(x=c(0,100000),y=c(0,1000000)
ggplot(otherdf,aes(x=X,y=Y)+geom_point(alpha=0.1)+geom_line(data=tlData,aes(x=x,y=y),color='red')
看来 ggplot 不再喜欢无数据几何组件,因为我使用的先前版本完全可以使用 aes(x=c(0,100000),y=c(0,100000)。
关于r - ggplot 在 geom_point 中给出 "arguments imply differing number of rows"错误,但它不是真的 - 如何调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26554745/