Heatmap by ggmap error and best practice

I want to build a heat map on ggmap.

library(ggmap) turku<-get_map('turku', zoom=13) turkumap<-ggmap(turku, extent="device", legend="topleft") turkumap turkumap+geom_density2d(mapping=aes(x = lon, y = lat),data = test, ) 

the error i get is:

  Error in (function (x, y, h, n = 25, lims = c(range(x), range(y))) : bandwidths must be strictly positive 

Control variable:

  test lon lat var1.pred 1 22.25320 60.4314 -67.04862 2 22.25332 60.4314 -67.07793 3 22.25344 60.4314 -67.11007 4 22.25356 60.4314 -67.14517 5 22.25368 60.4314 -67.18336 6 22.25379 60.4314 -67.22478 7 22.25391 60.4314 -67.26956 8 22.25403 60.4314 -67.31783 9 22.25415 60.4314 -67.36973 10 22.25427 60.4314 -67.42537 

Suggestions? There are many more entries in the variable test. What I want to build is the kriging result obtained with the krige function in the gstat library.

Is there a better way to do this?

I am open to very different decisions

+6
source share
1 answer

The problem is that lat values ​​are all the same. This means that the variance in the lat direction is zero, therefore, the throughput cannot be calculated to estimate the core density

You can hardcode the bandwidth,

 turkumap + geom_density2d(mapping=aes(x = lon, y = lat), data = test, h=0.01) 

but in your case, I would suggest not using geom_density2d for this particular dataset. Maybe just draw dots?

+6
source

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


All Articles