I'm trying to make a map of my study site using ggmap & Stamen maps. I've seen a few similar questions but haven't figured out a way to incorporate the solution into my Stamen map code.
I have two questions regarding this: 1. How can I custom label the points on the map? 2. How can I add a scale to maps in Stamen map? (either as a line indicating distance or something like x cm on map = y km in real life)
Tcoords <- read.csv("Tcoords.csv")
My file looks like this
# trap latitude longitude
1 52.34431 0.5374620
2 52.34281 0.5382080
3 52.34468 0.5406787
4 52.34357 0.5398280
5 52.34431 0.5397050
6 52.34516 0.5406294
In response to the suggestion, I've pasted the results to dput(head(Tcoords)) here:
structure(list(trap = c("1", "2", "3", "4", "5", "6"), latitude = c(52.344312,
52.342809, 52.3446849, 52.343572, 52.34431, 52.3451601), longitude = c(0.537462,
0.538208, 0.5406787, 0.539828, 0.539705, 0.5406294)), row.names = c(NA,
6L), class = "data.frame")
This the code I'm using to plot my points
center = c(lon = 0.5406294, lat = 52.3451601)
qmap(center, zoom = 16, source = "stamen", maptype = "watercolor")+
geom_point(aes(x = longitude, y = latitude), size = 4, shape = 21,
fill = "dark green", data = Tcoords)
But somehow trap isn't being recognised as an object. It's probably something elementary but I'm not really sure what I've missed (new to R). I've saved "trap" as a text object here.
Thanks for your help!


I would like to suggest
tmapas an alternative toggmap. This is one of many others possible packages for creating maps CRAN Task View: Spatial but I found the scale bar thattmapgenerates pretty nice and the code simple.The code to generate the final plot requires the following packages
Then, we read the coordinates of the six points to be mapped and turn them into an sf object
Next, we find the limits of the six points (bounding box) and extend them by a factor 2.5. You can play with this factor to get maps with other scales.
Finally we read the background map
and draw the final map
with the following code
To get a dynamic map is even simpler as you do not have read first the basemap (
read_osm) and then draw the map.In the static plot, colors, text and breaks in the scale can be personalized. Note the parameter
unit = "m"in thetm_shapein order to get the scale in meters, if not it will be in kilometers.Hope you will find this alternative worth mentioning.