Divergent Likert 5 point data
From https://www.snip2code.com/Snippet/67149/Create-divergent-stacked-bar-graph-using
# Set the working directory, not entirely necessary though
setwd("/PATH/TO/WORKING/DIRECTORY/something")
# import likert package
require(likert)
# Output to EPS
postscript("result-plot.eps", onefile=FALSE, horizontal=FALSE, height=2.5)
dataset <- read.table("plot-data.csv", header=TRUE, sep=",")
colnames(dataset)[which(names(dataset)=="column.1")] <- "Column 1"
colnames(dataset)[which(names(dataset)=="column.2")] <- "Column 2"
colnames(dataset)[which(names(dataset)=="column.3")] <- "Column 3"
colnames(dataset)[which(names(dataset)=="column.4")] <- "Column 4"
colnames(dataset)[which(names(dataset)=="column.5")] <- "Column 5"
# create colored plot
plotlevels <- c('Strongly Agree', 'Agree', 'Neutral', '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)
# Do the actual plotting
likert.bar.plot(experimentdataset)
# Close and write the file
dev.off()