0

I was attempting to geomap a contour heatmap of my data on top of a google map. However, I find a persistent problem.

When I create the contour map without adding a geographic map, the function works fine and gives me the following graphic.

enter image description here

CODE

 library(ggplot2)
 library(ggmap)

 latlonpostcandat<-data.frame(cbind(c(47.00735, 47.36228, 47.40399, 48.08666,47.57196, 
 47.63742),
 c(-52.95892, -53.29399, -52.79987, -52.89429, -53.27813, -52.92653),
 c(86301.14, 1017390.34, 2662332.67,  473139.73, 8251899.99,  167512.52)))

 names(latlonpostcandat)<-c('Longitude','Latitude','Trans_Amt')

 ggplot(latlonpostcandat,aes(x = Longitude, y = Latitude, z = Trans_Amt)) +
 geom_contour()

Now, when I do the exact same thing but execute the following code:

 map <- get_map(location='Canada', zoom=3, maptype = "terrain",
                source='google',color='color')
 ggmap(map)+ 
 ggplot(latlonpostcandat, aes(x = Longitude, y = Latitude, z = Trans_Amt)) + 
 geom_contour()

I get the following error: Error: Don't know how to add o to a plot

I feel there is something subtly wrong here that is preventing me from getting the results I expect.

Thank you for your time.

turbonstre
  • 21
  • 2
  • I do not have your data so there is no 100% guarantee. One thing I can tell is that you cannot use `ggplot()` with `ggmap()`. If I revise your code, I would do the following first. `ggmap(map) + geom_contour(data = latlonpostcandat, aes(x = Longitude, y = Latitude, z = Trans_Amt))`. – jazzurro Feb 16 '18 at 04:02
  • @jazzurro interesting! the code seems to run without the error `Don't know how to add o to a plot`. However, I now get an error saying `Computation failed in `stat_contour()`: total number of levels >= 2^31`. How would you go about fixing this error? – turbonstre Feb 16 '18 at 15:15
  • I have no clue of your data. So I cannot say anything about the error. You need to provide a minimal sample data so that SO users can reach your actual situation. Have a look of questions that have many upvotes. – jazzurro Feb 16 '18 at 15:32
  • I've provided a snippet of the data. Hopefully this can help. – turbonstre Feb 16 '18 at 16:01
  • @turbonstre You need to add column names to the dataframe containing your code. Please ensure the code you post executes w/o error. I would also add the needed `library` statements to your code for things like `ggplot2`, `ggmap`, etc. – steveb Feb 16 '18 at 16:08
  • 1
    Your data is not enough to produce contour. I recommend you to use `dput()`. Have a look of the function. This is how some SO users provide their sample data. – jazzurro Feb 16 '18 at 16:10
  • @steveb thank you for your reply and help. I have updated the code. Hopefully this helps. – turbonstre Feb 16 '18 at 16:11
  • Have a look of [**this question**](https://stackoverflow.com/questions/21290230/filled-contour-plot-with-r-ggplot-ggmap). This is one of the questions that can guide you through, I believe. – jazzurro Feb 16 '18 at 16:19
  • @jazzurro definitely looking in the right direction. However, I get the same error as previously mentioned: `Warning message: Computation failed in `stat_contour()`: total number of levels >= 2^31`. I feel like this is the last step that is preventing me from seeing what I want to show. – turbonstre Feb 16 '18 at 16:24
  • Once again, I have no clue, I am afraid. I highly recommend you to learn how to provide a sample data first. That helps both sides save time. – jazzurro Feb 16 '18 at 16:34

0 Answers0