]> code.communitydata.science - coldcallbot-discord.git/blob - data/track_participation.R
66ca3dbc7954808399090e991fea5fc4e066d84e
[coldcallbot-discord.git] / data / track_participation.R
1 library(ggplot2)
2
3 gs <- read.delim("student_information.tsv")
4 d <- gs[,c(2,5)]
5 colnames(d) <- c("student.num", "discord.name")
6
7 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x)[,1:3]}))
8 colnames(call.list) <- gsub("_", ".", colnames(call.list))
9
10 call.counts <- data.frame(table(call.list$discord.name))
11 colnames(call.counts) <- c("discord.name", "num.calls")
12
13 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
14
15 ## set anything that's missing to zero
16 d$num.calls[is.na(d$num.calls)] <- 0
17       
18 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
19
20 attendance.counts <- data.frame(table(attendance))
21 colnames(attendance.counts) <- c("discord.name", "num.present")
22
23 d <- merge(d, attendance.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
24
25
26 color.gradient <- scales::seq_gradient_pal("yellow", "magenta", "Lab")(seq(0,1,length.out=length(unique(d$num.present))))
27
28 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
29
30 ggplot(d) +
31     aes(x=as.factor(num.calls), fill=as.factor(num.present)) +
32     geom_bar(color="black") +
33     stat_count() +
34     scale_x_discrete("Number of questions asked") +
35     scale_y_continuous("Number of students") +
36     # scale_fill_brewer("Absences") +
37     scale_fill_manual("Absences", values=color.gradient) +
38     theme_bw()
39
40 dev.off()
41
42 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
43
44 ggplot(data=d) +
45     aes(x=as.factor(num.calls), y=num.present) +
46     geom_boxplot() +
47     scale_x_discrete("Number of questions asked") +
48     scale_y_continuous("Number of questions present")
49
50 dev.off()
51

Community Data Science Collective || Want to submit a patch?