Created
October 2, 2013 19:29
-
-
Save houshuang/6799251 to your computer and use it in GitHub Desktop.
Various plot likert functions for use with HH's likert
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
PlotLikert <- function(var1, var2, ...) { | |
likert(data.frame | |
(t | |
(unclass | |
(prop.table | |
(table(var1, var2),2)))), ...) | |
} | |
reshape.likert <- function(x, factors=c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"), columns="ALL") { | |
row.names(x) <- NULL | |
if (columns=="ALL") { cols <- x} else { cols <- x[,columns] } # choose relevant columns | |
cols <- sapply(cols, function(y) table(y)) # get summary counts for each line | |
cols <- t(cols) # flip the axis | |
cols <- cols[,factors] # resort the factors | |
return(cols) | |
} | |
plot.likert <- function(x, columns="ALL", title="Likert plot", xaxis=F, ...) { | |
y <- likert(reshape.likert(x, columns=columns), as.percent=T, main=title, ...) | |
if(xaxis != F) { y$y.limits <- xaxis } | |
plot(y) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment