1

I have created following choropleth map for cropland.

enter image description here

The code I used is:-

library(mapview)
library(dplyr)
library(sf)
setwd("C:/Users/lenovo/Desktop/IEM")
Province3Miscellaneous<-st_read("BagmatiProMiscellaneous.shp")
Province3Miscellaneous
View(Province3Miscellaneous)
Province3Miscellaneous<-st_set_crs(Province3Miscellaneous,'+init=EPSG:4326')
Province3Miscellaneous
View(Province3Miscellaneous)
mapview(Province3Miscellaneous, zcol="CULTI", col.region=colorRampPalette
    (c("goldenrod","goldenrod1","goldenrod2","goldenrod3","goldenrod4")))

The attribute table of the map data is:- enter image description here

However, I want the district name of each polygon to be displayed on the choropleth map. Is that possible in choropleth map? If yes, How?

2
  • How do you want it displayed? Do you want all the names to be visible all the time over the polygons they represent, like geom_sf_label does with a ggplot graphic, or do you want it visible on hover or click over the region?
    – Spacedman
    Jun 19 at 8:22
  • @Spacedman, I want all the names to be visible all the time over polygons with basemap as shown above .
    – Walker
    Jun 19 at 8:37

1 Answer 1

1

Specify the labels and the label options like this:

mapview(d, zcol="Z", label=d$CNTR_CODE, 
   labelOptions = labelOptions(noHide = TRUE, textOnly = TRUE)) 

Where d is my spatial data frame coloured by column "Z" and "CNTR_CODE" column has my label names in.

Leave out the textOnly=TRUE to change the style.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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