library(dplyr) library(xtable) options(xtable.comment = FALSE, xtable.floating = FALSE, xtable.timestamp = "") library(ggplot2) load("exam_data.RData") load("student_info.RData") base <- results %>% dplyr::select(student_id, score) %>% dplyr::group_by(student_id) %>% dplyr::summarize(score = sum(score, na.rm = TRUE)) %>% dplyr::ungroup() student_score <- as.numeric(base[base$student_id == student_id,"score"]) group_mean <- base %>% dplyr::select(-student_id) %>% dplyr::summarize(score = mean(score, na.rm = TRUE)) %>% as.numeric() if (student_score >= group_mean) col <- "darkgreen" else col <- "red"
Dear r first_name
,
This is the individual report associated to the student number r as.character(student_id)
. Table 1 displays your answers as recorded by the scanner, and the corresponding score. Please make sure that the scanner did not make a mistake when reading your answser sheet (cf. figure 1). Check also whether points were correclty computed. Figure 2 gives you an indication about your position among all the participants to the exam. Finally, figures 3 to 5 give a detail of the percentages of points you earned in each chapter, section, or subsection. We hope this information will help you identify and address your main weaknesses.
quest_nbr <- length(unique(answers$question)) tbreaks <- unique(c(seq(from = 5, to = 45, by = 5), quest_nbr)) tbreaks <- tbreaks[tbreaks <= quest_nbr] answers[answers$student_id == student_id,] %>% mutate(exam_id = as.character(exam_id)) %>% dplyr::select(-student_id) %>% xtable( digits = 2, caption = paste0("Answers recorded for the student id ", student_id)) %>% print( type = "latex", include.rownames = FALSE, format.args = list(big.mark = ",", decimal.mark = "."), size = "small", hline.after = c(-1, -1, 0, tbreaks), align = "ll|rrrrr", latex.environments = "center", caption.placement = "top", tabular.environment = "longtable", floating = FALSE )
base %>% ggplot(aes(x = score)) + geom_density() + geom_vline(xintercept = student_score, lty = 2, color = col) + annotate("text", x = student_score, y = 0.05, label = "Your\ngrade", color = col) + geom_vline(xintercept = group_mean, lty = 2, color = "blue") + annotate("text", x = group_mean, y = 0.025, label = "Group\nmean", color = "lightblue") + theme_bw()
reports[reports$student_id == student_id,] %>% dplyr::filter(level == "chapter") %>% dplyr::mutate(topic = reorder(topic, desc(topic))) %>% ggplot(aes(x = topic, y = percentage, fill = scope)) + geom_bar(stat = "identity", width = 0.5, position = position_dodge(width = 0.5)) + scale_fill_manual(values = c("lightblue", col)) + coord_flip() + ylim(0, 100) + theme_bw() + theme(legend.position = "bottom", legend.direction = "horizontal")
reports[reports$student_id == student_id,] %>% dplyr::filter(level == "section") %>% dplyr::mutate(topic = reorder(topic, desc(topic))) %>% ggplot(aes(x = topic, y = percentage, fill = scope)) + geom_bar(stat = "identity", width = 0.5, position = position_dodge(width = 0.5)) + scale_fill_manual(values = c("lightblue", col)) + coord_flip() + ylim(0, 100) + theme_bw() + theme(legend.position = "bottom", legend.direction = "horizontal")
reports[reports$student_id == student_id,] %>% dplyr::filter(level == "subsection") %>% dplyr::mutate(topic = reorder(topic, desc(topic))) %>% ggplot(aes(x = topic, y = percentage, fill = scope)) + geom_bar(stat = "identity", width = 0.5, position = position_dodge(width = 0.5)) + scale_fill_manual(values = c("lightblue", col)) + coord_flip() + ylim(0, 100) + theme_bw() + theme(legend.position = "bottom", legend.direction = "horizontal")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.