1

I'm plotting some points over a map using ggmap. This is the error message:

Removed 10 rows containing missing values (geom_point).

This is my code:

    library(ggmaps)
    library(maps)
    library(DataComputing)
    map <- get_map(location='san francisco', zoom=12, maptype = 'terrain', source = 'google', color = 'color')
    ggmap(map) %>%
    + geom_point(aes(x=longitude, y=latitude, colour = as.numeric(total)), data=district_crimes) %>%
    + scale_color_gradient(low='beige', high='blue')

Data frame

Proof that longitude and latitude are numeric.

How do get the points to plot? Thanks.

  • 1
    You inverted longitude/latitude, see http://stackoverflow.com/questions/15069963/getting-a-map-with-points-using-ggmap-and-ggplot2 – timfaber Apr 22 '17 at 09:47

1 Answers1

2

The suggestion of @timfaber is right. Longitude is placed on the x axis and latitude on the y axis, as you can see from the axes labels of the following plot:

ggmap(map)

enter image description here

Hence, the right way to plot points on your map is:

ggmap(map) +
 geom_point(aes(x=latitude, y=longitude, colour = as.numeric(total)), 
   size=4, data=district_crimes) +
scale_color_gradient(low='blue', high='red')

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58