In my specific requirement, I want to color just the neighbouring districts. First, I have downloaded the data:
library(sp)
library(mapproj)
library(rgeos)
library(raster)
library(GADMTools)
library(precrec)
library(ggplot2)
library(tidyverse)
library(sf)
library(dplyr)
library(plotly)
library(plotrix)
India <- getData("GADM", country = "India", level = 2)
India_Level1 <- raster::getData("GADM", country = "India", level = 1)
# dist level map
dist_level_map_Gujarat <- India %>% st_as_sf() %>% filter(NAME_1 == "Gujarat")
And then I can plot all the districts within the state of Gujarat :
p_Gujarat <- ggplot(data = dist_level_map_Gujarat) +
geom_sf(mapping = aes(fill = NAME_2)) +
theme_void() + theme(legend.position = "none")
ggplotly(p_Gujarat)
Which is good.
But then if I only want to color (preferably gradient color) using 'Centroid' as the district, and all the neighbors to it. I am trying something like this:
# using sf, get the centriods
dist_level_map_Gujarat_Centroids_sf <- st_centroid(dist_level_map_Gujarat)
dist_level_map_Gujarat$Centroid <- dist_level_map_Gujarat_Centroids_sf$geometry
# Extract X and Y values of Centroids
dist_level_map_Gujarat$Centroid_X <- sapply(dist_level_map_Gujarat$Centroid,"[[",1)
dist_level_map_Gujarat$Centroid_Y <- sapply(dist_level_map_Gujarat$Centroid,"[[",2)
And I want to use something similar as below (the circle around the centroid to color the gradients, for a circle of, say 100 Kms, to color the neighboring districts)
plot(1:5,seq(1,10,length=5),type="n",xlab="",ylab="",main="Test draw.circle", axes=FALSE,ann=FALSE)
draw.circle(3,6,c(1,0.66,0.33),border="purple", col=c("#ff00ff","#ff77ff","#ffccff"),lty=1,lwd=1)
But not sure how can I do that. Can someone please help?