Interrogation of underage victims with audio visual aids: time evolution between examination by the police and actual interrogation - janeshdev/ggplot2 GitHub Wiki
Interrogation of underage victims with audio-visual aids: time evolution between examination by the police and actual interrogation
By Ann Frederix, strategic analyst at Federal Police Belgium
Introduction
In Belgium it is strongly advised to interrogate underage victims with audio-visual aids. For this purpose special interrogators are trained, who apply a system of 7/7 24/24 permanency. By request of the public prosecutor, the efficiency of this permanency will be evaluated. Therefore the interrogators will complete a form during two months to register several points of time of an interrogation process. There are three points of time that are important to analyse the cases: the time the police has knowledge of a case involving an underage victim, the time the special interrogator is contacted and the time the actual interrogation starts.
Objective
We want to visualise the three individual points of time of every case in one plot. The x-axis is the registration period (13/08/2010-15/10/2010). We also want to colour the weekends within this period (every Friday 22 pm till Monday 06 am). As an extra, the names of the charge number (y-axis) will have a different color depending on the type of the case.
Ggplot gives a solution for this objective, combined with ‘legend’ (graphics).
Explanation of variable names
The variable names are abbreviations derived from Dutch words. Therefore a short list of explanation:
- AVV input (input audio-visual interrogation): original data (from SPSS)
- feiten (‘facts’): name of dataframe of original data
- dat_pol: the time the police has knowledge of a case involving an underaged victim
- dat_verh: the time the special interrogator is contacted
- dat_avv_start: the time the actual interrogation starts
- letter: charge number of the audio-visual interrogation (fictitiously)
- delict: type of case
- tijdstip (‘point of time’): variable name to combine all time variables
- weekend: for the Belgian police, a weekend is from Friday 22:00 pm till Monday 6:00 am
- kleur (‘color’): variable name of vector of colors
The code
#needed library’s
library(foreign) library(ggplot2) library(grid) library(RColorBrewer) library(car) library(reshape)
outputdirectory<-"G: /"
#data preparation
#read data:
feiten<-as.data.frame(read.spss("G:/AVV input.sav", use.value.labels = T))
#POSIX for date variables:
feiten$dat_pol<-as.POSIXct(feiten$dat_pol, origin="1582-10-14",tz="GMT") feiten$dat_verh<-as.POSIXct(feiten$dat_verh, origin="1582-10-14",tz="GMT") feiten$dat_avv_start<-as.POSIXct(feiten$dat_avv_start, origin="1582-10-14",tz="GMT")
#make dataframe with only the necessary variables:
data_plot<-feiten[,c("dat_pol","dat_verh","dat_avv_start","letter","delict")]
#order data:
data_plot$letter<-with(data_plot,reorder(reorder(letter,1/as.numeric(dat_pol)),1/as.numeric(dat_avv_start))) data_plot<-data_plot[order(data_plot$dat_pol,data_plot$dat_avv_start,decreasing=TRUE),]
#melt the 3 data variables to variable ‘tijdstip’:
data_plot.melt<-melt.data.frame(data_plot, id=c("letter ","delict"), variable_name = "tijdstip")
#make extra dataframe that determines beginning end ending of all weekends within the registration period of 2 months:
dtimes_lo=c("2010-08-13 22:00:00","2010-08-16 06:00:00","2010-08-20 22:00:00","2010-08-23 06:00:00","2010-08-27 22:00:00", "2010-08-30 06:00:00","2010-09-03 22:00:00","2010-09-06 06:00:00","2010-09-10 22:00:00","2010-09-13 06:00:00","2010-09-17 22:00:00", "2010-09-20 06:00:00","2010-09-24 22:00:00","2010-09-27 06:00:00","2010-10-01 22:00:00","2010-10-04 06:00:00","2010-10-08 22:00:00", "2010-10-11 06:00:00","2010-10-15 22:00:00") dtimes_lo<-as.POSIXlt(dtimes_lo)
dtimes_hi=c("2010-08-16 06:00:00","2010-08-20 22:00:00","2010-08-23 06:00:00","2010-08-27 22:00:00","2010-08-30 06:00:00","2010-09-03 22:00:00", "2010-09-06 06:00:00","2010-09-10 22:00:00","2010-09-13 06:00:00","2010-09-17 22:00:00","2010-09-20 06:00:00","2010-09-24 22:00:00","2010-09-27 06:00:00", "2010-10-01 22:00:00","2010-10-04 06:00:00","2010-10-08 22:00:00","2010-10-11 06:00:00","2010-10-15 22:00:00","2010-10-18 06:00:00") dtimes_hi<-as.POSIXlt(dtimes_hi)
we<-data.frame(start=dtimes_lo,end=dtimes_hi,weekend=c("weekend","week","weekend","week","weekend","week","weekend","week", "weekend","week","weekend","week","weekend","week","weekend","week","weekend","week","weekend"))
#rename levels variable ‘tijdstip’ (for legend):
levels(data_plot.melt$ tijdstip)<-c("knowledge police","knowledge special interrogator","interrogation audio-visual aids")
#add variable 'kleur' based on variable ‘delict’ (to color names of charge numbers on Y-axis according to type of case):
data_plot.melt$kleur<-recode(as.numeric(data_plot.melt$delict),'1="darkorchid1";2="darkturquoise";else="forestgreen"') kleur<-data_plot.melt$kleur
#draw the ggplot
plot<- ggplot(data_plot.melt,aes(value,letter)) + geom_point(aes(groups= tijdstip,colour= tijdstip,shape= tijdstip))+ xlab(NULL) + ylab(NULL)+ geom_rect(aes(NULL,NULL,xmin=start,xmax=end,ymin=0,ymax=(nrow(data_plot))+1,fill=weekend),data=we)+ opts(axis.text.x = theme_text(angle = 45, hjust = 1, size = 8)) + opts(legend.text = theme_text(hjust=0, size = 8))+ opts(title = " Interrogation of underage victims with audio-visual aids: time evolution between examination by the police and actual interrogation ")+ opts(plot.title = theme_text(size = 12,face="italic",lineheight=20.0,hjust=0))+ opts(axis.text.y = theme_text(hjust=1,colour=kleur)) + labs(colour="point of time",shape="point of time")+ scale_x_datetime (major = "1 days",format = "%b-%d",expand=c(0,0))+ scale_fill_manual(values=alpha(c("lemonchiffon2","lightsalmon"),0.2))+ scale_colour_manual(values = c("royalblue4","limegreen","mediumvioletred")) + scale_shape_manual(values = c(0,1,2)) + scale_y_discrete(expand=c(0,0))
#add extra legend (colors charge numbers)
plot.new() vp1<- viewport(width=0.90,height=1.0,x=0.50,y=0.50) vp2<-viewport(width=0.4,height=0.4,x=0.75,y=0.35)
#print to png
png(file=paste(outputdirectory,"time.png"),width=30,height=11,units="cm",res=100,restoreConsole=TRUE) plot.new() print(plot,vp=vp1) print(legend(0.79,1.1,bty="n",legend= c("type1","type2","type3"),text.col=c("darkorchid1","darkturquoise","forestgreen"), cex=0.7,y.intersp=1.5),vp=vp2) dev.off()
Note: this is a temporary plot. The final plot will include cases untill the 15th of October.