Ggplot gives "arguments imply a different number of lines" error in geom_point, until it is so - how to debug?

I have two objects of type Large SpatialPointsDataFrame named st2 and st10 . They come from one source. They both build without problems:

plot(st2) 

or

 plot(st10) 

But I want to build them using ggmap and ggplot. I can do this for st2 with simple code:

 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 the 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's wrong? I have more than 20 of these SP data frames, and some of the plots, well others, give the error mentioned above ... this is not related to the number of points

What could be wrong? Or maybe someone can give me some advice on how I can debug this?

+5
source share
1 answer

I got around this by creating 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 to have geometric components without data, since the previous version I used was fine using aes (x = c (0,100000), y = c (0,100000).

+2
source

Source: https://habr.com/ru/post/1205468/


All Articles