Skip to content

Instantly share code, notes, and snippets.

@houshuang
Created October 2, 2013 19:29
Show Gist options
  • Save houshuang/6799251 to your computer and use it in GitHub Desktop.
Save houshuang/6799251 to your computer and use it in GitHub Desktop.
Various plot likert functions for use with HH's likert
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