Search code examples
rleafletr-leaflet

R: Add title to Leaflet map


I'd like to add a title to the whole map (different from the legend title: addLegend(..., title = "", ...): by "title", I mean an overlaid map component that stays in place while the map is moved (unlike an overlaid image)what the map title could look like.

Is that an option in RStudio's leaflet for R?

leafletR has a title="" argument but it updates the title of the webpage: it does not add a title to the map.


Solution

  • You should provide a reproducible example. But using addControl you could try:

     library(leaflet)
     library(htmlwidgets)
     library(htmltools)
    
     rr <- tags$div(
       HTML('<a href="https://cran.r-project.org/"> <img border="0" alt="ImageTitle" src="/PathToImage/ImageR.jpeg" width="300" height="100"> </a>')
     )  
    
     map_leaflet <- leaflet() %>%
       addTiles() %>%
       addMarkers(50, 50) %>%
       addControl(rr, position = "bottomleft")
    
     saveWidget(map_leaflet, file="testing.html")
    

    Open testing.html saved in your working directory and you will see an image (just create an image with Map Title in it) over your map. It is not center you can only put the control on the four corners. Hope it helps!