My current code:
library(pdftools)
plot <- NA
Indicator <- unique(map_and_data$Indicator)
plot<-list (1:length(Indicator))
for (i in 1 : length(Indicator))
{
df = map_and_data[map_and_data$Indicator==Indicator[[i]],]
plot[[i]]<- ggplot()+
geom_sf(aes(fill=df$NFHS5),color="black",data=df$geometry)+
labs(title = Indicator[[i]])
ggsave("test.pdf", plot[[i]], device = "pdf")
}
What I want is to save all the plots(maps) in the same file. The issue is that it runs the loop and saves for the last Indicator(in this case it's 104) only. How should I go about solving this problem?