1
votes

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 stackoverflow.com/questions/15069963/…timfaber

1 Answers

2
votes

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