2

So I am currently figuring out how to overlay a contour onto a map, so far I have this. Any help would be appreciated. Thanks in advance.

worldmap = getMap(resolution = "high")
NrthAm = worldmap[which(worldmap$REGION =="North America"),]
plot(NrthAm, xlim=c(-123.35,-122.65),
     ylim=c(49,49.35), main = "Pokemon in Vancouver")

newnew = "CREATE VIEW location AS SELECT latitude, longitude FROM Vanpoke"
query1 = "SELECT latitude, longitude from location"
point = dbGetQuery(dbcon,query1)

kde = kde2d(point$longitude,point$latitude)
image(kde)
contour(kde)

Edit1: I added some sample data

   latitude longitude
1 49.33597 -123.0458
2 49.27268 -122.8834
3 49.25722 -122.9652
4 49.30699 -123.0204
5 49.19668 -122.9262
6 49.33281 -123.0636

Edit2: I added a the density plot onto a map, but I am not sure if it is correct or not.enter image description here

warmsoda
  • 57
  • 1
  • 9
  • 1
    Unless you want to give us access to your database (strongly discouraged), you're going to need to give us a sample of what you want from `query1` displayed on the map. And please advise on what non-base packages you are using, there may be ambiguity. Is this `rworldmap`? – r2evans Feb 14 '20 at 02:52
  • This question is fairly good, but consider how to make it *reproducible* so that it is much easier for somebody to just pick it up and try it (without access to your private data and database). This includes sample code (specifically here, listing non-base R packages), sample *unambiguous* data where it is not in a package (e.g., `dput(head(x))` or `data.frame(x=...,y=...)`), and expected output. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Feb 14 '20 at 02:54
  • Thank you for your reply, I am kinda new to all this. So I am using RSQLite, rworldmap and rworldextra for this problem. For query1, it is a table with longitude and latitde. I want it to display like a Cartesian system with x = longitude and y = latitude onto a map. – warmsoda Feb 14 '20 at 03:05
  • Please understand that *"it is a table with longitude and latitde"* is one thing, but we cannot use that description for anything other than a guess (is `runif(2,30,35)` and `runif(2,100,102)` good enough? If so, *use that*.). If you think we should consider some of that data for helping you with the problem, the onus is on you to give us something to use. I don't care that you're using `RSQLite`, you can simplify your question and just give sample data. Also, you appear to be using `MASS`, is that right? (It is a little discouraging for me to have to chase down this type of information.) – r2evans Feb 14 '20 at 03:47
  • I am so sorry for the lack of information since I am still figuring things out. I added some sample data and a plot to my post. Thank you for your time. – warmsoda Feb 14 '20 at 04:06

0 Answers0