Skip to content

Instantly share code, notes, and snippets.

@emres
Created May 24, 2013 20:12
Show Gist options
  • Save emres/5646197 to your computer and use it in GitHub Desktop.
Save emres/5646197 to your computer and use it in GitHub Desktop.
R source code that is used for producing the graphics used in the blog entry titled "Results of the survey: Why don’t we have secondary school textbooks with source code in them?"
## textbook.R
## Tested on:
## R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
library(ggplot2)
library(car)
setwd("~/Documents/programming/R/")
textbook <- read.csv("textbook.csv", na.strings = "")
isGreat <- textbook$Do.you.think.it.would.be.great.if.secondary.school.students.had.such.textbooks
isUsed <- textbook$Have.you.ever.used.such.a.book.during.YOUR.secondary.education
isCurrent <- textbook$Do.you.know.secondary.education.textbook.s...currently.in.use..with.source.code.samples.at.the.end.of.each.chapter
isGreat <- recode(isGreat, "NA='N/A'")
isUsed <- recode(isUsed, "NA='N/A'")
isCurrent <- recode(isUsed, "NA='N/A'")
cPalette1 <- c('black','red','blue')
cPalette2 <- c('red','blue')
png('isGreat.png')
p <- qplot(isGreat, geom="bar", fill=factor(isGreat),
main=" Do you think it would be great if secondary
school students had textbooks with source code?",
xlab = "")
p + scale_fill_manual(values=cPalette1) +
theme(legend.title=element_blank()) +
theme(axis.text=element_text(family = "Source Code Pro",
face="bold", size = 13)) +
theme(plot.title=element_text(family = "Source Code Pro",
face="bold", size = 13))
dev.off()
png('isUsed.png')
p <- qplot(isUsed, geom="bar", fill=factor(isUsed),
main="Have you ever used such a book during your
secondary education?",
xlab = "")
p + scale_fill_manual(values=cPalette2) +
theme(legend.title=element_blank()) +
theme(axis.text=element_text(family = "Source Code Pro",
face="bold", size = 13)) +
theme(plot.title=element_text(family = "Source Code Pro",
face="bold", size = 14))
dev.off()
png('isCurrent.png')
p <- qplot(isCurrent, geom="bar", fill=factor(isUsed),
main=" Do you know secondary education textbook(s)
(currently in use) with source code samples
at the end of each chapter?",
xlab = "")
p + scale_fill_manual(values=cPalette2) +
theme(legend.title=element_blank()) +
theme(axis.text=element_text(family = "Source Code Pro",
face="bold", size = 13)) +
theme(plot.title=element_text(family = "Source Code Pro",
face="bold", size = 14))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment