Skip to content

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
survey visualization
#r code to read survey responses
#from a google spreadsheet published to web as .csv
#please see
#and the github
#for another method using google fusion tables
#require(vcd) #use vcd since I have never used it before
#ended up not using since I could not control size and location
#of the assoc plot
url <- "
responses <- read.csv (url, stringsAsFactors=FALSE)
#thanks to lamages for this date conversion (better than my old)
#mine different since in US with month/day/year and hour:minute:second
responses$Timestamp <- as.POSIXct(responses$Timestamp,
format="%m/%d/%Y %H:%M:%S")
#add some easier column names to the responses
colnames(responses) <- c("date","frequency","rating","comments","objective")
#code to do jpeg
#jpeg(filename="survey results.jpeg",quality=100,units="in",height=8,width=6,res=96)
#sets up the layout for plotting
#I still have a lot to learn here but maybe
#one more example might help someone out
#matrix will be
# [,1] [,2]
#[1,] 1 2
#[2,] 3 3
#[3,] 4 4
#so graph 1 and 2 will be in the first row
#3 will fill the entire second row and
#4 will fill the entire third row
#get some colors to use in the charts
colpal <- colorRampPalette(c("steelblue4","grey"),space="rgb")
#borrowed this also from lamages
#table summarizes
day <-$date,"day")),stringsAsFactors=FALSE)
#name the columns
colnames(day) <- c("day","freq")
plot(day$freq~as.Date(day$day),type="o",lwd=3,bty="n",xlab=NA,ylab="# of responses")
title(main="Analysis of Timely Portfolio Survey Results",
title(main="Responses by day",adj=0,line=0.5)
#gets same as above in matrix form for easier use of barplot
#could just do as.matrix(day)
day.matrix <- as.matrix(table(cut(responses$date,"day")))
#I assume there is an easier way to do this with tickmarks in the middle
#for now I will hack around it
title(main="Histogram of rating",adj=0,line=1)
#sort by frequency of visit; wish I would have made this numeric
#something like how often do you visit per month - 30,15,10,5,1
#but I'll just deal with this manually
#convert to a numeric value
#unique(responses$frequency) to see the responses for frequency of visit
responses[which(responses$frequency=="Daily"),2] = 30
responses[which(responses$frequency=="Several times each week"),2] = 15
responses[which(responses$frequency=="Once a week"),2] = 4
responses[which(responses$frequency=="Once a month"),2] = 1
responses[which(responses$frequency=="Less than Once a month"),2] = 0
responses$frequency = as.numeric(responses$frequency)
col=c("steelblue4","indianred4"),xlab="rating",ylab="visit frequency")
title(main="Association plot of rating and visit frequency",adj=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.