2

When using the R leaflet package, how can I add something additional to the attribution string (i.e. the "Leaflet | ..." in the bottom right corner)?

For example, I how would I add something like "data source: ..." to the attribution text on this map:

leaflet(data = quakes[1:20,]) %>% 
  addTiles() %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))
Matt SM
  • 235
  • 3
  • 13

2 Answers2

4

As @rensa suspects, their second option does indeed embed and fetch both tile sets. However, the setting a blank urlTemplate seems to stop it:

leaflet(data = quakes[1:20,]) %>% 
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addTiles(urlTemplate = "", attribution = 'I did this, you hear?! Also Leaflet.')
3

You can add an attribution argument to addTiles:

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

I'd love to know how to do this with addProviderTiles, though, because that doesn't appear to accept an attribution argument :/

EDIT: okay, my workaround for using provider tiles has been to just use both functions. I hope it's not actually calling both tiles, since that's a bit of a waste of user bandwidth—but hey, it looks fine!

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))
jimjamslam
  • 1,988
  • 1
  • 18
  • 32