Visualization of ranked likert-scale using advanced dot plot
I wish to produce a graph presenting responses to a number of agreement statements. The graph should allow for comparisons across the different groups of respondents and statement items.
I basically draw on a R code provided by Kastellec & Leoni (Figure 5; http://tables2graphs.com/doku.php?id=03_descriptive_statistics#figure_5).
In contrast to them, I would like to have the x-axis ranging from -5 to 5 and the table should be in the format of 2x2.
This code should produce sample data similar to the one I used:
mydata<-expand.grid( col1=c('item1', 'item2', 'item3', 'item4'), col2=c('0', '1', '3', '4'), col3=c('T1', 'T2', 'C1', 'C2')) mydata$col4=sapply(rnorm(64,0,1), function(x) {round(x,2)})
Note:
- col1: statement item („variable“ in the data set of K&L)
- col2: answer category ("period" in K&L)
- col3: group of respondent ("legislature" in K&L)
- col4: proportion ("proportion" in K&L)
And this is the code:
library(lattice) library(car) ltheme <- canonical.theme(color = FALSE) ltheme$strip.background$col <- "lightgrey" lattice.options(default.theme = ltheme) mydata$col2<-factor(mydata$col2, levels=c(0,1,3,4), labels=c("strongly disagree", "disagree", "agree", "strongly agree"), ordered=TRUE) mydata$col3<-factor(mydata$col3, levels=c("T1", "C1", "T2", "C2"), ordered=TRUE) levels(mydata$col3)<-c("treatment group 1", "control group 1", "treatment group 2", "control group 2") mydata$col1<-factor(mydata$col1, levels=c("item1", "item2", "item3", "item4"), labels=c("item 4", "item 3", "item 2", "item 1"), ordered=TRUE) prop.vec<-c(-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5) plot<-dotplot(mydata$col1~mydata$col4|mydata$col3, xlab="levels of agreement", data=mydata, groups=mydata$col2, layout=c(2,2), scales=list(cex=0.65, x=list(at=prop.vec), alternating=3), par.strip.text=list(lines=2.5,cex=0.65), panel=function(...){ panel.abline(v=prop.vec, col="lightgrey") panel.abline(h=1:11, col="lightgrey", lty=2) panel.xyplot(...)}, as.table=TRUE, par.settings=simpleTheme(pch=c(19,1,2,17), cex=0.7), auto.key=list(space="bottom", column=4, cex=0.65) ) trellis.device(file="figure.pdf", device="pdf", color=FALSE, width=6, height=8) print(plot, newpage=FALSE) dev.off()
