cartography : display a background map

Hello,

I have a dataset containing georeferenced points. I can display these points but I would like to integrate a background map (satellite, basic background).

Here is an example of a dataset and the code to display these points:

library(sf)
library(ggplot2)

df <- data.frame(lon = c(7.389801812, 7.382449389, 7.384940219, 7.387570357, 7.37491467, 7.37739296, 7.379973102, 7.372087193, 7.382560379, 7.385341144, 7.387903333),
                 lat = c(48.42369, 48.42901459, 48.4289978, 48.42880688, 48.43111324, 48.43098717, 48.43107758,  48.43283577, 48.43077007, 48.43071995, 48.43046265),
                 mean = c(2, 5, 8, 4, 3, 5, 7, 9, 2, 10, 9)
)   

df1 <- st_as_sf(df, coords = c("lon", "lat"), crs = st_crs(df))

ggplot(df1) +
  geom_sf() +
  geom_point(
    aes(colour = mean, size = mean, geometry = geometry),
    stat = "sf_coordinates"
  )

The "get_map" or "leaflet" function could perhaps allow to display a background map (satellite, basic background) but I don't see how to integrate the function in my script, I'm a beginner in the field of cartography on R.

If you have ideas to display background maps behind my georeferenced points I'm interested!

Thank you,
David

You may consider the {ggmap} approach shown in this older post: Best packages for making map? leaflet vs ggmap vs sf vs ...? - #2 by jlacko

Satellite might be more complex, but regular terrain or toner from Stamen are often good enough options.

1 Like

Thanks, ggmap and ggplot work well together. The background maps: "terrain", "terrain-background" are not bad.

But do you know a way to get an "Open Street Map" type background with ggmap? Without having to enter an API Key.

Thank you,
David

For Open Street Map background tiles you will want to look into ggmap::get_openstreetmap() documentation.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.