Skip to content
Browse files

Updated likert code.

  • Loading branch information...
1 parent ec23655 commit d0827653ff57b026ba19996148a28e7308eb2a95 @jbryer committed Apr 27, 2012
Showing with 61 additions and 59 deletions.
  1. +10 −11 R/likert.R
  2. +18 −15 irutils.test.R
  3. +3 −3 man/plot.likert.Rd
  4. +15 −15 man/plot.likert.bar.Rd
  5. +15 −15 man/plot.likert.heat.Rd
View
21 R/likert.R
@@ -132,27 +132,26 @@ summary.likert <- function(x, ...) {
#' @param neutral.color color for middle values. Only used when there are an odd
#' number of levels.
#' @param text.size size or text labels
+#' @param text.color the color of text in heat map cells
#' @param type whether to plot a bar or heat map graphic
#' @export
#' @method plot likert
#' @S3method plot likert
-plot.likert <- function(likert, low.color='blue', high.color='red',
- neutral.color='white', text.colour='white', text.size=2,
- type=c('bar','heat'), ...)
-{
+plot.likert <- function(likert, text.size=2, type=c('bar','heat'), ...) {
if(type[1] == 'bar') {
- plot.likert.bar(likert, low.color=low.color, high.color=high.color,
- neutral.color=neutral.color, text.size=text.size, ...)
+ plot.likert.bar(likert,
+ #low.color=low.color, high.color=high.color, neutral.color=neutral.color,
+ text.size=text.size, ...)
} else {
- plot.likert.heat(likert, low.color=low.color, high.color=high.color,
+ plot.likert.heat(likert, #low.color=low.color, high.color=high.color,
text.size=text.size, ...)
}
}
#' Internal method.
#' @seealso plot.likert
plot.likert.bar <- function(likert, low.color='blue', high.color='red',
- neutral.color='white', text.size=2, ...)
+ neutral.color='white', text.size=2, text.color='black', ...)
{
lowrange = 1 : ceiling(likert$nlevels / 2 - likert$nlevels %% 2)
highrange = ceiling(likert$nlevels / 2 + 1 ) : likert$nlevels
@@ -206,8 +205,8 @@ plot.likert.bar <- function(likert, low.color='blue', high.color='red',
#' Internal method.
#' @seealso plot.likert
-plot.likert.heat <- function(likert, low.color='blue', high.color='red',
- neutral.color='white', text.colour='white', text.size=2, ...) {
+plot.likert.heat <- function(likert, low.color='white', high.color='blue',
+ neutral.color='white', text.color='black', text.size=2, ...) {
if(!is.null(likert$grouping)) {
stop('likert plots with grouping are not supported.')
}
@@ -221,7 +220,7 @@ plot.likert.heat <- function(likert, low.color='blue', high.color='red',
label=paste(format(mean, digits=3, drop0trailing=FALSE),
' (', format(sd, digits=2, drop0trailing=FALSE), ')', sep='')),
size=text.size) +
- geom_tile() + geom_text(size=text.size, colour=text.colour) + coord_flip() +
+ geom_tile() + geom_text(size=text.size, colour=text.color) + coord_flip() +
scale_fill_gradient("Percent", low=low.color, high=high.color, limits=c(0,100)) +
xlab('') + ylab('') +
opts(panel.grid.major=theme_blank(),
View
33 irutils.test.R
@@ -3,12 +3,10 @@ library(ggplot2)
theme_update(panel.background=theme_blank(), panel.grid.major=theme_blank(), panel.border=theme_blank())
-
-#Testing the plotting functions
#How much do you agree or disagree with these statements about reading?
-data(pisa)
+data(pisana)
-items28 = pisa[,substr(names(pisa), 1,5) == 'ST24Q']
+items28 = pisana[,substr(names(pisana), 1,5) == 'ST24Q']
head(items28); ncol(items28)
names(items28) = c("I read only if I have to.",
"Reading is one of my favorite hobbies.",
@@ -27,19 +25,17 @@ for(i in 1:ncol(items28)) {
}
l28 = likert(items28)
-print(l28)
+summary(l28)
+
plot(l28)
plot(l28, type='heat')
-l28g = likert(item28, grouping = pisa$CNT)
-
-plotBarchartTable(items28, low.color='maroon', high.color='burlywood4')
-plotBarchartTable(items28, grouping=pisa$CNT, low.color='maroon', high.color='burlywood4')
-plotHeatmapTable(items28)
-
+#Group by country
+l28g = likert(items28, grouping = pisana$CNT)
+plot(l28g, low.color='maroon', high.color='burlywood4')
#How often do you read these materials because you want to?
-items29 = pisa[,substr(names(pisa), 1,5) == 'ST25Q']
+items29 = pisana[,substr(names(pisana), 1,5) == 'ST25Q']
head(items29); ncol(items29)
names(items29) = c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers")
for(i in 1:ncol(items29)) {
@@ -48,8 +44,15 @@ for(i in 1:ncol(items29)) {
'Several times a month', 'Several times a week'), ordered=TRUE)
}
-plotBarchartTable(items29, low.color='maroon', high.color='burlywood4') +
+l29 = likert(items29)
+summary(l29)
+
+plot(l29, low.color='maroon', high.color='burlywood4') +
opts(title="How often do you read these materials because you want to?")
-plotBarchartTable(items29, grouping=pisa$CNT, low.color='maroon', high.color='burlywood4') +
+plot(l29, type='heat') + opts(title="How often do you read these materials because you want to?")
+
+l29g = likert(items29, grouping=pisana$CNT)
+summary(l29g)
+
+plot(l29g, low.color='maroon', high.color='burlywood4') +
opts(title="How often do you read these materials because you want to?")
-plotHeatmapTable(items29) + opts(title="How often do you read these materials because you want to?")
View
6 man/plot.likert.Rd
@@ -2,9 +2,7 @@
\alias{plot.likert}
\title{Plots a set of likert items.}
\usage{
- \method{plot}{likert} (likert, low.color = "blue",
- high.color = "red", neutral.color = "white",
- text.colour = "white", text.size = 2,
+ \method{plot}{likert} (likert, text.size = 2,
type = c("bar", "heat"), ...)
}
\arguments{
@@ -21,6 +19,8 @@
\item{text.size}{size or text labels}
+ \item{text.color}{the color of text in heat map cells}
+
\item{type}{whether to plot a bar or heat map graphic}
}
\description{
View
30 man/plot.likert.bar.Rd
@@ -1,15 +1,15 @@
-\name{plot.likert.bar}
-\alias{plot.likert.bar}
-\title{Internal method.}
-\usage{
- plot.likert.bar(likert, low.color = "blue",
- high.color = "red", neutral.color = "white",
- text.size = 2, ...)
-}
-\description{
- Internal method.
-}
-\seealso{
- plot.likert
-}
-
+\name{plot.likert.bar}
+\alias{plot.likert.bar}
+\title{Internal method.}
+\usage{
+ plot.likert.bar(likert, low.color = "blue",
+ high.color = "red", neutral.color = "white",
+ text.size = 2, text.color = "black", ...)
+}
+\description{
+ Internal method.
+}
+\seealso{
+ plot.likert
+}
+
View
30 man/plot.likert.heat.Rd
@@ -1,15 +1,15 @@
-\name{plot.likert.heat}
-\alias{plot.likert.heat}
-\title{Internal method.}
-\usage{
- plot.likert.heat(likert, low.color = "blue",
- high.color = "red", neutral.color = "white",
- text.colour = "white", text.size = 2, ...)
-}
-\description{
- Internal method.
-}
-\seealso{
- plot.likert
-}
-
+\name{plot.likert.heat}
+\alias{plot.likert.heat}
+\title{Internal method.}
+\usage{
+ plot.likert.heat(likert, low.color = "white",
+ high.color = "blue", neutral.color = "white",
+ text.color = "black", text.size = 2, ...)
+}
+\description{
+ Internal method.
+}
+\seealso{
+ plot.likert
+}
+

0 comments on commit d082765

Please sign in to comment.
Something went wrong with that request. Please try again.