0

I am trying to plot points on a map using R and plotGoogleMaps. I have a dataframe that I am attempting to use but I can not figure out how to do it.

My code is:

df <- data.frame(dbGetQuery(con, paste('select * from googlemaps')))

An example of the out to this is:

      T1141      LAT       LNG
1     A/BCD 51.48503 -0.062313
2     B/CDE 51.56495 -0.078709
3     C/DEF 51.54829 -0.0469517

The next code I use is this: coordinates(df) <- ~LAT+LNG

But this gives me the following error:

Error in .checkNumericCoerce2double(obj) : cannot retrieve coordinates from non-numeric elements

What am I doing wrong here?

EDIT:

I tried checking the mode of the column as suggested in the comment and this was the result:

coordinates(df) <- ~LAT+LNG Error in .checkNumericCoerce2double(obj) : cannot retrieve coordinates from non-numeric elements

mode(df$LAT) [1] "numeric"

mode(df$LNG) [1] "numeric"

  • Have you tried checking the type of the LAT and LNG columns? From the error it looks like they should be numeric but maybe they are stored as factors or strings in `df`. Try `mode(df$LAT)` or `mode(df$LNG)` to check. If it is a character or factor use `as.numeric` to do the conversion. – Stefan Avey Jul 24 '14 at 15:28
  • @av1 sorry for the slow reply ... I tried what you suggested and this was my results: `> coordinates(df) <- ~LAT+LNG Error in .checkNumericCoerce2double(obj) : cannot retrieve coordinates from non-numeric elements > mode(df$LAT) [1] "numeric" > mode(df$LNG) [1] "numeric" – user3825794 Jul 30 '14 at 08:39
  • Can you provide a reproducible example with the real or toy data? – Stefan Avey Jul 30 '14 at 20:00

0 Answers0