I want to add a basemap to my plot, which visualizes three SpatialPointDataFrames.
I've already tried the maptools as well as RgoogleMaps package, but both don't work in the way, which I want to.
My problem: The SpatialPointDataFrames are not drawn on the GoogleMaps Background map.
A minimal example:
The city.csv with the following example content:
FID,city,POINT_X,POINT_Y
0,New York,-73.996786,40.720813
1,Newark,-74.172237, 40.732196
The R Code:
# Load packages
library(RgoogleMaps)
library(sp)
# load .csv file
city= read.csv("city.csv", header = TRUE)
# convert to SpatialPointDataFrame
coordinates(city) <- c("POINT_X", "POINT_Y")
proj4string(city) <- CRS("+proj=longlat +datum=WGS84")
# use RgoogleMaps
gc <- geocode('new york, usa')
center <- as.numeric(gc)
ggmap(get_googlemap(center = center, color = 'bw', scale = 4), fullpage = T)
# Plot the city dataset
plot(city, pch = 22, col="black", bg= "yellow", cex = 1.5, add = TRUE)
The result should be a plot with the background map and the two points, but the points are not drawn on the map. Is there a geocoding problem or do I miss anything? Is it possible to combine ggmap and plt functions?
Any help is much appreciated!