I have created following map for disaster by district as shown below.
The code I used is:-
install.packages("cartography")
install.packages("sf")
install.packages("tidyverse")
library(cartography)
library(sf)
library(tidyverse)
setwd("C:/Users/lenovo/Desktop/IEM")
Province2Disaster<-st_read("DisasterBagmatiProvince.shp")
View(Province2Disaster)
Province2Disaster$DeathClass<-cut(Province2Disaster$Deaths,
breaks = c(0,500,1500,3000,4500, Inf),
labels=c('<500','50-1500','1500-3000','3000-4500','>4500'))
ggplot()+geom_sf(aes(fill=DeathClass),data=Province2Disaster)+
ggtitle("Total Death by Disaster in Province 2")
But I want to label feature by district name (dist_name) as shown in attribute table.
But using the code (after the code above) :-
ggplot()+geom_sf(aes(fill=DeathClass),data=Province2Disaster)+
geom_text(aes(label = dist_name))+
ggtitle("Total Death by Disaster in Province 2")
The error display as:- Error in FUN(X[[i]], ...) : object 'dist_name' not found
. Though the column name dist_name is present in table. Why is this occuring? How to fix it?