Reputation: 121
My goal is to make a map and put locations on that map. It would be similar to this R geom_point and ggmap but I can get the map, but having a hard time even getting the points to show up.
Here is the code I am using.
require(ggmap)
library(ggmap)
pp<- data.frame(lat=c(48.8535, 48.85418333, 48.86253333, 48.86373333, 48.86698333, 48.87033333, 48.87281667, 48.86993333, 48.87718333, 48.86251667,
48.85313333, 48.89153333, 48.88231667, 48.84368333, 48.84221667, 48.84473333, 48.8335, 48.86961667, >48.84681667), lon=c(-122.5735333, -122.54085, -122.5142667,
-122.4969667, -122.4857333, -122.4646, -122.44245, -122.4372167, -122.4128167, -122.4298, -122.48205, -122.40875, -122.4423833, -122.55515, -122.5196667, -122.52105
, -122.5086333, -122.4067667, -122.4358833))
tenmile <- get_map(location = c(lon = -122.486328, lat = 48.862813),
color = "color",
source = "google",
maptype = "roadmap",
zoom = 12)
ggmap(tenmile,
extent = "device",
ylab = "Latitude",
xlab = "Longitude")
p<- ggmap(tenmile) + geom_point(data=pp, aes(x=lon, y=lat), color="red", size=30, alpha=0.5)
Upvotes: 2
Views: 458
Reputation: 145775
I think your only problem is that you're not assigning your initial map to an object. Try this:
# Assign to variable
tenmile.map <- ggmap(tenmile,
extent = "device",
ylab = "Latitude",
xlab = "Longitude")
# Then add the points to the base map you created.
p <- tenmile.map + geom_point(data=pp, aes(x=lon, y=lat),
color="red", size=30, alpha=0.5)
p
If you want you could combine these, but you still have to do all your map specifications:
all.in.one <- ggmap(tenmile,
extent = "device",
ylab = "Latitude",
xlab = "Longitude") +
geom_point(data=pp, aes(x=lon, y=lat),
color="red", size=30, alpha=0.5)
all.in.one
One last comment: there are very small differences between library()
and require()
, but they both load the package and you only need to use one of them. Lots of details in this question if you're interested.
Upvotes: 4