This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(sp)
## Warning: package 'sp' was built under R version 3.4.3
library(RColorBrewer)
#readRDS("IND_adm1.rds")
ind1=readRDS("IND_adm1.rds")
spplot(ind1, "NAME_1", scales=list(draw=T), colorkey=F, main="India")
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
class(ind1)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
ind1$NAME_1=as.factor(ind1$NAME_1)
ind1$fake.data=runif(length(ind1$NAME_1))
spplot(ind1,"NAME_1", col.regions=rgb(0,ind1$fake.data,0), colorkey=T, main="Indian States")
ind1$NAME_1
## [1] Andaman and Nicobar Andhra Pradesh Arunachal Pradesh
## [4] Assam Bihar Chandigarh
## [7] Chhattisgarh Dadra and Nagar Haveli Daman and Diu
## [10] Goa Gujarat Haryana
## [13] Himachal Pradesh Jammu and Kashmir Jharkhand
## [16] Karnataka Kerala Lakshadweep
## [19] Madhya Pradesh Maharashtra Manipur
## [22] Meghalaya Mizoram Nagaland
## [25] NCT of Delhi Odisha Puducherry
## [28] Punjab Rajasthan Sikkim
## [31] Tamil Nadu Tamil Nadu Telangana
## [34] Tripura Uttar Pradesh Uttarakhand
## [37] West Bengal
## 36 Levels: Andaman and Nicobar Andhra Pradesh Arunachal Pradesh ... West Bengal
wb1 = (ind1[ind1$NAME_1=="West Bengal",])
spplot(wb1,"NAME_1", col.regions=rgb(0,0,1), main = "West Bengal, India",scales=list(draw=T), colorkey =F)
kt1 = (ind1[ind1$NAME_1=="Karnataka",])
spplot(kt1,"NAME_1", col.regions=rgb(0,1,0), main = "Karnataka, India",scales=list(draw=T), colorkey =F)
ind2=readRDS("IND_adm2.rds")
wb2 = (ind2[ind2$NAME_1=="West Bengal",])
spplot(wb2,"NAME_1", main = "West Bengal Districts", colorkey =F)
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
wb2$NAME_2 = as.factor(wb2$NAME_2)
col = rainbow(length(levels(wb2$NAME_2)))
spplot(wb2,"NAME_2", col.regions=col, colorkey=T)
wb2$NAME_2 = as.factor(wb2$NAME_2)
wb2$fake.data = runif(length(wb2$NAME_1))
spplot(wb2,"NAME_2", col.regions=rgb(0,wb2$fake.data, 0), colorkey=T)
col_no = as.factor(as.numeric(cut(wb2$fake.data, c(0,0.2,0.4,0.6,0.8,1))))
levels(col_no) = c("<20%", "20-40%", "40-60%","60-80%", ">80%")
wb2$col_no = col_no
myPalette = brewer.pal(5,"Greens")
spplot(wb2, "col_no", col=grey(.9), col.regions=myPalette, main="District Wise Data")
ind3=readRDS("IND_adm3.rds")
wb3 = (ind3[ind3$NAME_1=="West Bengal",])
wb3$NAME_3 = as.factor(wb3$NAME_3)
col = rainbow(length(levels(wb3$NAME_3)))
spplot(wb3,"NAME_3", main = "Taluk, District - West Bengal", colorkey=T,col.regions=col,scales=list(draw=T))
wb3 = (ind3[ind3$NAME_1=="West Bengal",])
n24pgns3 = (wb3[wb3$NAME_2=="North 24 Parganas",])
spplot(n24pgns3,"NAME_3", colorkey =F, scales=list(draw=T), main = "24 Pgns (N) West Bengal")
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
n24pgns3 = (wb3[wb3$NAME_2=="North 24 Parganas",])
basirhat3 = (n24pgns3[n24pgns3$NAME_3=="Basirhat",])
spplot(basirhat3,"NAME_3", colorkey =F, scales=list(draw=T), main = "Basirhat,24 Pgns (N) West Bengal")
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
wb2 = (ind2[ind2$NAME_1=="West Bengal",])
wb2$NAME_2 = as.factor(wb2$NAME_2)
col = rainbow(length(levels(wb2$NAME_2)))
spplot(wb2,"NAME_2", col.regions=col,scales=list(draw=T),ylim=c(23.5,25),xlim=c(87,89), colorkey=T)
library(ggmap) # -- for geocoding, obtaining city locations
## Warning: package 'ggmap' was built under R version 3.4.3
## Loading required package: ggplot2
ind2 = readRDS("IND_adm2.rds")
# plotting districts of a State, in this case West Bengal
wb2 = (ind2[ind2$NAME_1=="West Bengal",])
nam = c("Purulia","Bankura","Midnapur")
pos = geocode(nam)
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Purulia&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Bankura&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Midnapur&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Midnapur"
tlat = pos$lat+0.05 # -- the city name will be above the marker
cities = data.frame(nam, pos$lon,pos$lat,tlat)
names(cities)[2] = "lon"
names(cities)[3] = "lat"
text1 = list("panel.text", cities$lon, cities$tlat, cities$nam,col="red", cex = 0.75)
mark1 = list("panel.points", cities$lon, cities$lat, col="blue")
text2 = list("panel.text",87.0,26.0,"GADM map", col = "dark green", cex = 1.2)
spplot(wb2, "NAME_1",
sp.layout=list(text1,mark1, text2),
main="West Bengal Districts",
colorkey=FALSE, scales=list(draw=TRUE))
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
## Warning in Ops.factor(z, at[i]): '>=' not meaningful for factors
## Warning in Ops.factor(z, at[i + 1]): '<' not meaningful for factors
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.