]> projects.mako.cc - noahs_yelp_analysis/commitdiff
r code and data to generate bar graphs
authorBenjamin Mako Hill <mako@atdot.cc>
Sun, 8 Apr 2012 21:26:07 +0000 (17:26 -0400)
committerBenjamin Mako Hill <mako@atdot.cc>
Sun, 8 Apr 2012 21:26:07 +0000 (17:26 -0400)
analysis.R [new file with mode: 0644]
lord-hobo-cambridge.txt [new file with mode: 0644]

diff --git a/analysis.R b/analysis.R
new file mode 100644 (file)
index 0000000..13ccaf3
--- /dev/null
@@ -0,0 +1,36 @@
+cat("\n","Enter textfile name","\n") # prompt
+y<-readLines(n=1) 
+x <- paste("lord-hobo-cambridge.txt",sep="")
+d <- read.csv(x)[,c(1,2,3)]
+
+colnames(d) <- c("rating", "day.of.week", "day.in.review")
+d$day.in.review <- d$day.in.review == "True"
+
+d$day.of.week <- as.character(d$day.of.week) 
+d$day.of.week[d$day.of.week == "0"] <- "Sunday"
+d$day.of.week[d$day.of.week == "1"] <- "Monday"
+d$day.of.week[d$day.of.week == "2"] <- "Tuesday"
+d$day.of.week[d$day.of.week == "3"] <- "Wednesday"
+d$day.of.week[d$day.of.week == "4"] <- "Thursday"
+d$day.of.week[d$day.of.week == "5"] <- "Friday"
+d$day.of.week[d$day.of.week == "6"] <- "Saturday"
+d$day.of.week <- factor(d$day.of.week, levels = c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))
+
+d$day.of.week <- as.factor(d$day.of.week) 
+
+t <- table(d$day.of.week, as.factor(d$rating))
+t2 <- prop.table(t,2)
+chisq.test(d$day.of.week, as.factor(d$rating))
+
+# draw a graph
+library(ggplot2)
+v <- paste(y,"-baaaarplot.png",sep="")
+png(v, width=8, height=6, unit="in", res=200)
+p <- qplot(day.of.week, data=d, fill=as.factor(rating), main=y)
+#p <- qplot(levels(d$day.of.week),as.factor(names(d$rating)), t, data=data.frame(t,levels(d$day.of.week)))
+p <- p + scale_x_discrete("Day of Week") + scale_y_continuous("yelp # star review") + scale_fill_discrete("") 
+print(p)
+dev.off()
+
+
+
diff --git a/lord-hobo-cambridge.txt b/lord-hobo-cambridge.txt
new file mode 100644 (file)
index 0000000..05a0e4d
--- /dev/null
@@ -0,0 +1,235 @@
+4,4,False,
+3,5,False,
+1,3,False,
+1,3,False,
+4,0,True,
+4,5,True,
+4,3,False,
+4,4,False,
+4,6,False,
+5,2,False,
+4,6,True,
+4,6,False,
+3,2,False,
+2,0,False,
+5,6,False,
+5,0,False,
+5,4,False,
+4,5,False,
+5,5,False,
+4,0,False,
+5,6,False,
+4,2,False,
+5,3,False,
+4,3,False,
+4,6,False,
+5,6,True,
+4,5,True,
+4,5,False,
+4,0,False,
+4,2,False,
+3,2,False,
+3,5,False,
+5,0,False,
+4,3,False,
+1,1,False,
+4,6,False,
+5,5,False,
+3,3,False,
+4,2,False,
+5,3,False,
+5,0,False,
+3,5,True,
+3,2,False,
+2,6,False,
+4,3,False,
+3,4,False,
+5,6,False,
+2,1,False,
+3,3,False,
+4,3,False,
+4,0,False,
+1,5,False,
+5,0,False,
+4,0,False,
+2,2,False,
+4,3,False,
+3,2,False,
+4,0,False,
+3,2,False,
+4,6,False,
+4,1,False,
+5,2,False,
+2,1,False,
+5,2,False,
+4,4,False,
+2,6,False,
+1,0,False,
+1,0,True,
+1,2,False,
+4,5,True,
+1,1,False,
+1,6,False,
+3,4,False,
+3,5,False,
+3,1,False,
+3,4,False,
+3,2,False,
+3,2,False,
+3,4,False,
+3,0,False,
+3,4,False,
+3,6,False,
+5,2,False,
+4,0,True,
+4,0,False,
+3,1,True,
+3,1,False,
+5,0,True,
+2,6,True,
+4,5,True,
+2,0,True,
+4,1,False,
+2,5,True,
+4,5,False,
+3,2,False,
+4,1,False,
+3,0,False,
+4,6,True,
+5,5,False,
+2,5,True,
+4,4,False,
+4,1,False,
+4,6,False,
+4,4,False,
+4,3,False,
+4,4,False,
+3,6,True,
+1,3,False,
+4,6,False,
+4,3,False,
+2,6,False,
+4,0,False,
+4,3,False,
+3,1,False,
+3,4,False,
+4,0,False,
+5,1,False,
+1,0,False,
+3,2,False,
+4,2,False,
+3,2,False,
+4,0,False,
+2,2,False,
+4,2,True,
+3,5,False,
+4,6,True,
+4,4,True,
+2,4,False,
+2,6,False,
+4,5,True,
+2,2,False,
+3,6,False,
+3,6,True,
+2,3,False,
+4,4,False,
+3,2,True,
+4,2,False,
+4,4,False,
+3,5,False,
+1,5,False,
+4,3,False,
+4,5,True,
+4,5,False,
+3,1,False,
+4,4,False,
+2,6,True,
+5,4,False,
+4,5,True,
+4,1,False,
+2,4,False,
+3,3,False,
+3,5,True,
+5,5,True,
+2,5,False,
+5,2,False,
+3,4,False,
+3,5,False,
+2,2,False,
+3,4,False,
+4,5,True,
+2,4,False,
+4,2,False,
+3,5,True,
+4,3,True,
+3,4,False,
+3,3,False,
+3,0,False,
+3,1,False,
+3,0,False,
+4,1,False,
+4,0,False,
+3,3,False,
+3,2,False,
+1,2,False,
+1,3,False,
+4,0,False,
+1,0,True,
+3,4,False,
+4,2,True,
+4,5,False,
+4,3,True,
+3,4,False,
+2,3,False,
+4,0,False,
+4,5,True,
+3,0,False,
+4,2,False,
+5,0,False,
+4,1,False,
+4,4,False,
+4,2,False,
+3,2,True,
+2,0,False,
+3,4,False,
+3,5,False,
+1,0,True,
+1,5,False,
+4,5,False,
+4,2,True,
+3,3,False,
+4,0,True,
+4,0,False,
+2,4,True,
+4,6,False,
+2,4,False,
+3,3,False,
+4,0,False,
+4,1,False,
+4,6,False,
+3,6,True,
+3,0,False,
+4,2,False,
+1,0,False,
+1,0,True,
+2,3,False,
+3,2,False,
+3,0,False,
+1,1,True,
+4,4,False,
+5,2,True,
+2,3,False,
+5,3,True,
+2,6,True,
+5,1,False,
+3,6,False,
+2,1,False,
+4,1,False,
+1,6,False,
+3,2,False,
+4,4,False,
+5,6,True,
+2,6,False,
+3,6,False,
+4,3,False,
+4,5,False,

Benjamin Mako Hill || Want to submit a patch?