Created
January 8, 2012 20:58
-
-
Save mages/1579665 to your computer and use it in GitHub Desktop.
R vignette survey analysis
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
### Copyright 2012 Markus Gesmann | |
### markus dot gesmann at gmail dot com | |
### | |
### This file is made available under the terms of the GNU General Public | |
### License, version 2, or at your option, any later version, | |
### incorporated herein by reference. | |
### | |
### This program is distributed in the hope that it will be | |
### useful, but WITHOUT ANY WARRANTY; without even the implied | |
### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
### PURPOSE. See the GNU General Public License for more | |
### details. | |
### | |
### You should have received a copy of the GNU General Public | |
### License along with this program; if not, write to the Free | |
### Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
### MA 02110-1301, USA | |
### Code behind following blog entry: | |
### http://lamages.blogspot.com/2012/01/feedback-from-vignette-survey.html | |
require(googleVis) | |
### Survey data is hosted as a fusion table on Google Docs | |
url <- "http://www.google.com/fusiontables/api/query?sql=SELECT+*+FROM+2587957" | |
srvyData <- read.csv(url, stringsAsFactors=FALSE) | |
srvyData$Timestamp <- as.POSIXct(srvyData$Timestamp, | |
format="%d/%m/%Y %H:%M:%S") | |
### Survey submissions over time ### | |
dfHour <- as.data.frame(table(cut(srvyData$Timestamp, "hour"))) | |
names(dfHour) <- c("DateTime", "Submissions") | |
dfHour$DateTime <- format(as.POSIXct(dfHour$DateTime, | |
format="%Y-%m-%d %H:%M:%S"), | |
"%b-%d %H:%M") | |
dfDay <- as.data.frame(table(cut(srvyData$Timestamp, "day"))) | |
names(dfDay) <- c("DateTime", "Submissions") | |
dfDay$DateTime <- format(as.POSIXct(dfDay$DateTime, | |
format="%Y-%m-%d"), "%Y-%b-%d") | |
Chart.visits.per.hour <- gvisAreaChart(data=dfHour, "DateTime", "Submissions", | |
options=list(legend="none", | |
title="Survey submission per hour", | |
height=300), | |
chartid="visits_per_hour") | |
plot(Chart.visits.per.hour) | |
Chart.visits.per.day <- gvisAreaChart(data=dfDay, "DateTime", "Submissions", | |
options=list(legend="none", | |
title="Survey submissions per day", | |
height=300), chartid="visits_per_day") | |
plot(Chart.visits.per.day) | |
### Length ### | |
Length <- as.data.frame(table(srvyData$Length..Number.of.pages.)) | |
Length <- transform(Length, Freq=round(Freq/sum(Freq)*100,2)) | |
names(Length) <- c("Label" , "% of Submissions") | |
levels(Length$Label)[levels(Length$Label) %in% ""] <- "No answer" | |
Chart.vignette.length <- gvisColumnChart(Length, xvar="Label", | |
"% of Submissions", | |
options=list(legend="none", | |
hAxis="{textPosition: 'out'}", | |
vAxis="{title:'% of Submissions'}", | |
title="Length", | |
height=300), | |
chartid="vignette_length") | |
plot(Chart.vignette.length) | |
### Language ### | |
Language <- as.data.frame(table(srvyData$Language)) | |
Language <- transform(Language, Freq=round(Freq/sum(Freq)*100,2)) | |
names(Language) <- c("Label" , "% of Submissions") | |
levels(Language$Label)[levels(Language$Label) %in% ""] <- "No answer" | |
levels(Language$Label) <- gsub(" and ", ", ", levels(Language$Label)) | |
levels(Language$Label) <- gsub(" but ", ", ", levels(Language$Label)) | |
Chart.language <- gvisColumnChart(Language, xvar="Label", "% of Submissions", | |
options=list(legend="none", | |
hAxis="{textPosition: 'out', slantedTextAngle: '20'}", | |
title="Language", | |
vAxis="{title:'% of Submissions'}", | |
height=350), chartid="language") | |
plot(Chart.language) | |
## Structure ### | |
Structure <- srvyData[,4:10] | |
names(Structure) <- c("Introduction", "Motivation", "Examples", | |
"Road map", "Support", "Case studies", | |
"References") | |
strResult <- t(apply(apply(Structure,2, as.numeric), 2, | |
table)) | |
strResult <- apply(strResult, 1, function(x) | |
round(x/nrow(srvyData)*100,2)) | |
strResult <- data.frame(t(strResult)) | |
strResult <- data.frame(Section=rownames(strResult), strResult) | |
names(strResult) <- c("Section", "Not really needed", "Nice to have", | |
"Required") | |
Chart.structure <- gvisBarChart(strResult, options=list(legend="top", | |
hAxis="{title:'% of submission'}", | |
title="Structure"), | |
chartid="structure") | |
plot(Chart.structure) | |
## Examples ### | |
Examples <- data.frame(table(srvyData$Examples)) | |
Examples <- transform(Examples, Freq=round(Freq/sum(Freq)*100, 2)) | |
names(Examples) <- c("Label" , "% of Submissions") | |
levels(Examples$Label)[levels(Examples$Label) %in% ""] <- "No answer" | |
names(Examples)[1] <- "Usage of examples" | |
Chart.examples <- gvisTable(Examples, options=list(sortColumn=1, | |
sortAscending=FALSE, height=370), | |
chartid="examples") | |
plot(Chart.examples) | |
## Good Vignettes ### | |
trim <- function (x) gsub("^\\s+|\\s+$", "", x) | |
## trim: courtesy of http://stackoverflow.com/questions/2261079/whitespace-in-r | |
pckgs <- strsplit(paste(gsub("\n", ",", | |
levels(srvyData$Examples.of.good.vignettes)), | |
collapse=","), ",") | |
pckgs <- trim(pckgs[[1]]) | |
pckgs <- pckgs[! pckgs %in% c("", "?") ] | |
pckgs <- data.frame(table(tolower(pckgs))) | |
names(pckgs) <- c("Label", "Freq") | |
pckgs$Label <- as.character(pckgs$Label) | |
names(pckgs)[1] <- "Examples of good vignettes" | |
Chart.good.vignettes <- gvisTable(pckgs, options=list(sortColumn=1, | |
sortAscending=FALSE, | |
height=580), | |
chartid="good_vignettes") | |
plot(Chart.good.vignettes) | |
### Secrets of good vignettes ### | |
Secrets.of.good.vignettes <- | |
data.frame(levels(srvyData$What.is.the.secret.of.a.good.vignette.)) | |
names(Secrets.of.good.vignettes)="Secrets of good vignettes" | |
Chart.secrets <- gvisTable(Secrets.of.good.vignettes, | |
options=list(height=750), | |
chartid="secrets") | |
plot(Chart.secrets) | |
### What eles ### | |
What.else <- data.frame(levels(srvyData$What.else.)) | |
names(What.else) <- "What else?" | |
Chart.what.else <- gvisTable(What.else, options=list(height=250), | |
chartid="what_else") | |
plot(Chart.what.else) | |
########################## | |
### Expertise ### | |
Expertise <- table(srvyData$Your.R.expertise) | |
Expertise <- transform(Expertise, Freq=round(Freq/sum(Freq)*100, 2)) | |
names(Expertise) <- c("Label" , "% of Submissions") | |
levels(Expertise$Label)[levels(Expertise$Label) %in% ""] <- "No answer" | |
Chart.expertise <- gvisColumnChart(Expertise, xvar="Label", | |
"% of Submissions", | |
options=list(legend="none", | |
vAxis="{title: '% of Submissions'}", | |
title="Expertise"), | |
chartid="expertise") | |
plot(Chart.expertise) | |
### Usage of vignettes ### | |
vgnUsage <- data.frame(table(srvyData$How.much.do.you.use.vignettes.)) | |
vgnUsage <- transform(vgnUsage, Freq=round(Freq/sum(Freq)*100,2)) | |
names(vgnUsage) <- c("Label" , "% of Submissions") | |
levels(vgnUsage$Label)=c("1 Not at all", "2", "3", "4", | |
"5 Whenever available") | |
Chart.vignette.usage <- gvisAreaChart(vgnUsage, | |
options=list(legend="none", | |
hAxis="{textPosition: 'out', title: 'Rating scale'}", | |
vAxis="{title:'% of Submissions'}", | |
title="Usage of vignettes"), | |
chartid="vignette_usage") | |
plot(Chart.vignette.usage) | |
### Felt the pain? ### | |
pain <- | |
data.frame(table(srvyData$Have.you.written.technical.documentation.)) | |
pain <- transform(pain, Freq=round(Freq/sum(Freq)*100,1)) | |
names(pain) <- c("Label" , "% of Submissions") | |
levels(pain$Label)[levels(pain$Label) %in% ""] <- "No answer" | |
names(pain)[1] <- "Have you written technical documentation?" | |
Chart.pain <- gvisTable(pain, options=list(height=250) | |
,chartid="pain") | |
plot(Chart.pain) | |
### Merge all charts into one page ### | |
M <- gvisMerge( | |
Chart.visits.per.hour, | |
gvisMerge(Chart.visits.per.day, | |
gvisMerge(Chart.vignette.length, | |
gvisMerge(Chart.language, | |
gvisMerge(Chart.structure, | |
gvisMerge(Chart.examples, | |
gvisMerge(Chart.good.vignettes, | |
gvisMerge(Chart.secrets, | |
gvisMerge(Chart.what.else, | |
gvisMerge(Chart.expertise, | |
gvisMerge(Chart.vignette.usage, | |
Chart.pain))))))))))) | |
plot(M) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment