public
Last active

R vignette survey analysis

  • Download Gist
R_vignette_survey.R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
### 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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.