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, 1, 1, 1, 0, 1, 1, 0, 0, 3, 4, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 3, 1, 1, 1, 0, 1, 3, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 2, 1, 2, 0, 2, 2, 0, 0, 0, 2, 0, 0, 1, 0, 1, 3, 1, 1, 1, 1, 2, 1, 0, 0, 2, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 3, 1, 0, 4, 1, 0, 2, 0, 1, 1, 0, 2, 2, 1, 1, 1, 0, 0, 1, 1, 0, 2, 1, 1, 0, 1, 0, 1, 1, 1, 0, 2, 0, 0, 1, 0, 0, 2, 5, 1, 2, 1, 1, 1, 1, 0, 1, 2, 0, 2, 1, 1, 1, 2, 3, 1, 0, 2, 0, 2, 1, 1, 2, 0, 2, 0, 2, 3, 1, 0, 1, 1, 0, 0, 2, 1, 2, 1, 2, 0, 1, 2, 1, 2, 1, 0, 0, 3, 4, 0, 1, 0, 0, 2, 1, 0, 1, 1, 1, 1, 3, 1, 1, 0, 0, 2, 3, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 3, 0, 2, 1, 2, 0, 2, 1, 0, 2, 1, 1, 1, 0, 1, 1, 1, 3, 0, 0, 1, 1, 1, 1, 1) # Read in the other data # You'll need to change the filepath to wherever you've saved the file! dicedata = read.csv("/Users/matt/Desktop/dicedata.csv", header=FALSE) jarB = dicedata$V1 jarC = dicedata$V2 jarD = dicedata$V3 # Here are the various bits of code we used in class, with JarA as the # example. # Mean and standard deviation: mean(jarA) sd(jarA) # 95% Error bound: qt(0.975, 1599)*sd(jarA)/sqrt(1600) # lower and upper limits: mean(jarA) - qt(0.975, 1599)*sd(jarA)/sqrt(1600) mean(jarA) + qt(0.975, 1599)*sd(jarA)/sqrt(1600) # Putting it all into vectors for plotting. Values <- c(mean(jarA),mean(jarB), mean(jarC), mean(jarD)) Errors <- c(qt(0.975, 1599)*sd(jarA)/sqrt(1600), qt(0.975, 1599)*sd(jarB)/sqrt(1600), qt(0.975, 1599)*sd(jarC)/sqrt(1600), qt(0.975, 1599)*sd(jarD)/sqrt(1600)) # Dynamite Plot. Basic code taken from: # http://www.r-bloggers.com/dynamite-plots-in-r/ dynamitePlot <- function(height, error, names = NA, significance = NA, ylim = c(0,maxLim), ...){ maxLim <- 1.1* max(mapply(sum, height, error)) bp <- barplot(height, names.arg = names, ylim = ylim, ...) arrows(x0 = bp, y0 = height, y1 = height + error, angle = 90) text(x = bp, y = 0.2 + height + error, labels = significance) } Names <- paste("Jar", 1:4) #Sig <- c("95%", "95%", "95%", "95%") dynamitePlot(Values, Errors, names = Names) # (Add significance levels via "significance = Sig" in the command) # A better approach with points and error bars. # This will only work if you have ggplot2 installed. library(ggplot2) df <- data.frame(x = 1:4, y = Values, ymin = Values - Errors, ymax = Values + Errors) ggplot(data = df,aes(x = x,y = y)) + geom_point() + geom_errorbar(aes(ymin = ymin,ymax = ymax)) # In both plots, titles, axis lables and whatnot can (and should!) be added via the usual commands.