I want to make a map of India with state boundaries using the leaflet package in R. In the map, I want to make a heat map with the number of COVID cases in all states of India.
The data frames are as follows:
- sw - It contains name of states, total confirmed cases
- states - geo json file containing state names
The code is as follows:
sw <- data.frame(read_csv("state_wise.csv")) states <- geojsonio::geojson_read("states.geojson", what = "sp") states$Cases <- sw[match(states$ST_NM, sw$State), "Confirmed"] bins <- c(0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 100000, 200000, 250000, Inf) pal <- colorBin( palette = "viridis", domain = states$Cases, bins = bins ) map$labels <- paste0( "<strong> State: </strong> ", states$ST_NM, "<br/> ", "<strong> Cases: </strong> ", states$Cases, "<br/> " ) %>% lapply(htmltools::HTML) leaflet(states) %>% addTiles() %>% setView(lng = 0, lat = 30, zoom = 1.5) %>% addPolygons( fillColor = ~ pal(Cases), color = "white", fillOpacity = 0.7, label = ~labels, highlight = highlightOptions( color = "black", bringToFront = TRUE ) )
When I run this code, I get an error like this: Error in as.character(text) :
cannot coerce type 'closure' to vector of type 'character'
I am not able to understand where is this error coming from. Please help me out.