Last active
January 3, 2016 14:19
-
-
Save abhirupkgp/8475006 to your computer and use it in GitHub Desktop.
Analysis of the data on Crime against Women in India in 2012.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
library(RColorBrewer) | |
crimeW12 <- read.csv(url("http://data.gov.in/access-point-download-count?url=http://data.gov.in/sites/default/files/crdCAW_1.csv"), header = TRUE) | |
load(url("http://biogeo.ucdavis.edu/data/gadm2/R/IND_adm1.RData")) | |
#divide the data set into different crime headers | |
temp <- crimeW12[,c(1,4)] | |
crimeRep1 <- data.frame(State = temp[1:38,1], | |
Rape = temp[1:38,2], Kidnap = temp[39:76,2], | |
DowryDeath = temp[77:114,2], Assault = temp[115:152,2], | |
Insult = temp[153:190,2], Husband = temp[191:228,2], | |
Import = temp[229:266,2], Sati = temp[267:304,2], | |
Traffic = temp[305:342,2], Indecent = temp[343:380,2], | |
Dowry = temp[381:418, 2], Total = temp[419:456,2]) | |
crimeRep <- crimeRep1[-c(29,37,38),] | |
temporder <- crimeRep[order(crimeRep$State),] | |
gadm$Rape <- temporder$Rape | |
gadm$Kidnap <- temporder$Kidnap | |
gadm$DowryDeath <- temporder$DowryDeath | |
gadm$Assault <- temporder$Assault | |
gadm$Insult <- temporder$Insult | |
gadm$Husband <- temporder$Husband | |
gadm$Import <- temporder$Import | |
gadm$Sati <- temporder$Sati | |
gadm$Traffic <- temporder$Traffic | |
gadm$Indecent <- temporder$Indecent | |
gadm$Dowry <- temporder$Dowry | |
gadm$Total <- temporder$Total | |
#plot state wise crime | |
spplot(gadm, "Rape", col.regions = col, at = c(0,50,100,200, 500,1000, 1500,2000,2500,4000), main = "Rape") | |
spplot(gadm, "Kidnap", col.regions = col, at = c(0,50,100,200, 500,1000,2000,3000,5000,8000), main = "Kidnapping and Abduction") | |
spplot(gadm, "DowryDeath", col.regions = col, at = c(0,25, 50,100,250, 500,1000, 1500,2000,2500), main = "Dowry Death") | |
spplot(gadm, "Assault", col.regions = col, at = c(0,50,100,200, 500,1000,2000,3000,5000,7000),main = "Assault") | |
spplot(gadm, "Insult", col.regions = col, at = c(0,50,100,250,500,1000,1500,2000,3000,4000),main = "Insult to Modesty") | |
spplot(gadm, "Husband", col.regions = col, at = c(0,50,100,250,500,1000,2500,5000,10000,20000),main = "Cruelty by Husband and Others") | |
spplot(gadm, "Import", col.regions = col, at = c(0,5,10,20,30,50,100,200,500,1000),main = "Importing Girls") | |
spplot(gadm, "Sati", col.regions = col, at = c(0,5,10,15,20,30),main = "Sati") | |
spplot(gadm, "Traffic", col.regions = col, at = c(0,10,25,50,100,150,200,300,400,500),main = "Immoral Traffic") | |
spplot(gadm, "Indecent", col.regions = col, at = c(0,5,10,25,50,75,100), main = "Indecent Representation") | |
spplot(gadm, "Dowry", col.regions = col, at = c(0,50,100,250,500,1000,1500,2000,2500,3000),main = "Dowry") | |
spplot(gadm, "Total", col.regions = col, at = c(0,100,500,1000,2500,5000,10000,15000,25000,32000),main = "Total cases") | |
# clustering | |
row.names(crimeRep) <- crimeRep$State | |
crimeRep <- subset(crimeRep, select=-State) | |
d <- dist(crimeRep) | |
par(mfrow = c(1,3)) | |
hcs <- hclust(d, "single") | |
hca <- hclust(d, "average") | |
hcc <- hclust(d, "complete") | |
plot(hcs,frame.plot = TRUE) | |
plot(hca,frame.plot = TRUE) | |
plot(hcc,frame.plot = TRUE) | |
par(mfrow = c(1,1)) | |
plot(hcc,frame.plot = TRUE) | |
rect.hclust(hcc, k = 5, border = "red") | |
dt <- dist(t(crimeRep[,-12])) | |
par(mfrow = c(1,3)) | |
hcst <- hclust(dt, "single") | |
hcat <- hclust(dt, "average") | |
hcct <- hclust(dt, "complete") | |
plot(hcst,frame.plot = TRUE) | |
plot(hcat,frame.plot = TRUE) | |
plot(hcct,frame.plot = TRUE) | |
par(mfrow = c(1,1)) | |
plot(hcct,frame.plot = TRUE) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment