I have two objects of type Large SpatialPointsDataFrame named st2 and st10. They come from the same source. They both plot without problems with:
plot(st2)
or
plot(st10)
But I want to plot them with ggmap and ggplot. I can do this for st2 with a simple code like this:
map <- get_map(location = 'Poznań', zoom = 12)
ggmap(map) + geom_point(aes(x =st2@coords[,1], y = st2@coords[,2]))
But when it comes to st10 I get an error:
Error in data.frame(x = c(16.910848618, 16.910863876, 16.910913467, 16.910936356, :
arguments imply differing number of rows: 53885, 4
I check the values with length():
> length(st10@coords[,1])
[1] 53885
> length(st10@coords[,2])
[1] 53885
I check them with 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
What is wrong? I have over 20 of those SP data frames and some of the plot well other give the error mentioned above...this is not related to number of points
What can be wrong? Or maybe someone can give me some tips how can i debug this?
I got around this by making a new data frame.
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')
It seems that ggplot no longer likes have data-less geom components, as the prior version I used was perfectly okay with using aes(x=c(0,100000),y=c(0,100000).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With