2

I am using mapview in R to plot maps. I have more tha 100 polygons and I want to show them on the map with the names on it every time. But I couldn’t find a solution to this issue. Any idea?

mp<-st_read('https://raw.githubusercontent.com/mgaitan/departamentos_argentina/master/departamentos-buenos_aires.json',stringsAsFactors= FALSE)
mapview(mp,zcol='cabecera') 

I attached the image of my map. I want the names of the polygons (such as "Tres Arroyos") in every polygon ALL THE TIME.

enter image description here

2
  • Which names? Are the names an attribute of the map data? Are you trying to label the polygons? Or is it a legend with 100 items? Can you post an image of what you've got and maybe some code too?
    – Spacedman
    Mar 21, 2023 at 21:43
  • Thank you very much @Spacedman for your comments. I have already edited the question with more information. Mar 21, 2023 at 22:37

1 Answer 1

0

You can use leaflet and the function addStaticLabels() from the package leafem to add labels to the polygons.

Something like this:

mp=st_read('https://raw.githubusercontent.com/mgaitan/departamentos_argentina/master/departamentos-buenos_aires.json',stringsAsFactors= FALSE)
map = leaflet(mp)
mapview(dataX, zcol = "cabecera", addStaticLabels(map=map, data=mp, label = mp$departamento))

It may be be cluttered and ugly, but the labels will be there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.