[R Scripts] Visualising Likert Scale Responses Using likert

I am working with a data set from a survey, carried out as part of a user experience study, and recently got into an interesting discussion with my supervisor regarding data visualization. We touched on a couple of important issues–when to graphically represent information, types of visualizations… He suggested I look into using diverging stacked bar plots. I immediately went looking and discovered the likert R package. Incidentally, I also came across interesting articles [1, 2, 3] that touch on how to visualize Likert scales.

In the past [4], I’ve used traditional stacked bar plots to represent this sort of data. While this is equally generally accepted, the sub-responses in the data I am working with make ‘diverging stacked bar plots’ desirable. More details about the likert package are here [5].

Dataset

I am pulling my results from a LimeSurvey [6] instance and so I don’t have to pre-process or melt it; it’s already in an appropriate format. Sample data set used is attached.

Installing likert package

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages("likert")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'http://star-www.st-andrews.ac.uk/cran/src/contrib/likert_1.1.tar.gz'
Content type 'application/x-gzip' length 1677229 bytes (1.6 Mb)
opened URL
==================================================
downloaded 1.6 Mb

* installing *source* package ‘likert’ ...
** package ‘likert’ successfully unpacked and MD5 sums checked
** R
** data
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (likert)

The downloaded source packages are in
        ‘/tmp/Rtmp60MkrD/downloaded_packages’
>

Sample R Code

# import likert package
require(likert)

# I want to send output to PDF; uncomment nex line if you're working with TikZ
pdf("liket.bar.plot.dat")
#
dataset <- read.table("liket.bar.plot.dat", header=TRUE, sep=",")

colnames(dataset)[which(names(dataset)=="It.helps.me.be.more.effective")] <- "Helps me be more effective"
colnames(dataset)[which(names(dataset)=="It.feels.unnecessary.to.use.the.system")] <- "Feels unnecessary to use system"
colnames(dataset)[which(names(dataset)=="It.does.not.meet.my.expected.requirements")]  <- "Does not meet my requirements"
colnames(dataset)[which(names(dataset)=="It.helps.me.be.more.productive")] <- "Help me be more productive"
colnames(dataset)[which(names(dataset)=="It.feels.like.I.have.little.control.over.what.is.happening.with.the.activities")] <- "Offers little control over activities"
colnames(dataset)[which(names(dataset)=="It.is.useful")] <- "It is useful"
colnames(dataset)[which(names(dataset)=="I.find.it.difficult.to.get.things.done.with.the.system")] <- "I find it difficult to do things"
colnames(dataset)[which(names(dataset)=="It.gives.me.more.control.over.the.activities")] <- "Gives more control over activities"
colnames(dataset)[which(names(dataset)=="It.makes.the.things.I.want.to.accomplish.easy.to.get.done" )] <- "It makes things easy to do"
colnames(dataset)[which(names(dataset)=="It.saves.me.time.when.I.use.it")] <- "It saves me time"
colnames(dataset)[which(names(dataset)=="It.meets.my.needs")] <- "It meets my needs"
colnames(dataset)[which(names(dataset)=="It.does.everything.I.would.expect.it.to.do")] <- "It does everything expected"
colnames(dataset)[which(names(dataset)=="It.takes.up.a.lot.of.time")] <- "It takes up a lot of time"

# create colored plot
plotlevels <- c('Strongly Agree', 'Agree', 'Somewhat Agree', 'Neutral', 'Somewhat Disagree', 'Disagree', 'Strongly Disagree')

tryCatch({
   lbad <- likert(dataset)
}, error=function(e) {
   print("This is good that an error was thrown!")
   print(e)
})

sapply(dataset, class)
sapply(dataset, function(x) { length(levels(x)) } )

for(i in seq_along(dataset)) {
   dataset[,i] <- factor(dataset[,i], levels=plotlevels)
}

experimentdataset <- likert(dataset)

likert.bar.plot(experimentdataset, plot.percent.high=FALSE, plot.percent.low=FALSE,plot.percent.neutral=FALSE) +
theme_gray() +
scale_colour_stata() +
             theme(legend.title=element_blank(),
                   legend.position="bottom",
                   legend.text=element_text(size=8),
                   legend.key.height=unit(0.15,"cm"),
                   plot.margin=unit(c(0.1,0.1,0,0),"cm"),
                   strip.text = element_text(size=8),
                   axis.title.x = element_text(vjust=-0.8,size=8),
                   axis.title.y = element_text(vjust=-0.2,size=8),
                   axis.text = element_text(size=8),
                   #plot.text = element_text(size=8),
                   axis.text.x = element_text(angle=0,vjust=0.5)) +
             scale_fill_stata(breaks=c('Strongly Agree', 'Agree', 'Somewhat Agree', 'Neutral', 'Somewhat Disagree', 'Disagree', 'Strongly Disagree'), guide=guide_legend(ncol=4, byrow=TRUE))

Sample Output

Sample like Package Output Using a Seven-point Likert Scale

Sample like Package Output Using a Seven-point Likert Scale

Bibliography

[1] http://stats.stackexchange.com/q/25109/11682
[2] http://stats.stackexchange.com/q/3921/11682
[3] https://www.amstat.org/membersonly/proceedings/2011/papers/300784_64164.pdf
[4] http://lightonphiri.org/blog/using-r-ggplot2-package-for-elegant-graphics
[5] https://github.com/jbryer/likert
[6] https://www.limesurvey.org

Categories: Research, Technical
Tags: ,