library(plyr) library(tidyverse) library(gridExtra) library(cowplot) library(data.table) #source('CI-Functions.R') source('CI-Functions-Bonferroni.R') defaultpath <- dirname(rstudioapi::getActiveDocumentContext()$path) setwd(defaultpath) # Select phase to analyze, for the analysis per task we consider only the main phase #phase <- '_main' phase <- '_training' file_data <- paste0('aggregated_data', phase,'.csv') if (exists ('mydata')) { rm(mydata) } mydata <- read.table(file_data, header=T, sep=',') mydata$question_code <- gsub('C', 'CO', mydata$question_code) mydata$question_code <- gsub('A', 'CO', mydata$question_code) mydata$question_code <- gsub('B', 'CO', mydata$question_code) mydata$question_code <- gsub('D', 'MA', mydata$question_code) mydata$question_code <- gsub('E', 'MA', mydata$question_code) mydata$question_code <- gsub('F', 'MA', mydata$question_code) mydata$question_code <- gsub('I', 'SI', mydata$question_code) mydata$question_code <- gsub('G', 'SI', mydata$question_code) mydata$question_code <- gsub('H', 'SI', mydata$question_code) mydata$question_code <- gsub('J', 'CH', mydata$question_code) mydata$question_code <- gsub('K', 'CH', mydata$question_code) mydata$question_code <- gsub('L', 'CH', mydata$question_code) ## CALCULATE THE WIDTH AND HEIGHT library(stringr) interactions_data <- read.table('./data/user_interactions.csv', header=T, sep=',') screen_size <- interactions_data %>% filter(type_interaction=='screen_W_H') screen_size$args_interaction <- stringr::str_replace(screen_size$args_interaction, '\\)', '') screen_size$args_interaction <- stringr::str_replace(screen_size$args_interaction, '\\(', '') screen_size <- screen_size %>% separate(args_interaction, into = c('width', 'height'), sep = ', ') %>% select('user', 'width', 'height') %>% mutate(width=as.numeric(width), height=as.numeric(height)) %>% mutate(ratio=width/height) ## OVERALL TIMES AND ERROR d <- mydata %>% select(-c('X', 'question_internal_id')) %>% group_by(user, vis) %>% summarise(mean_time = mean(mean_time), mean_error = mean(mean_error), mean_conf = mean(mean_confidence), mean_dif = mean(mean_difficulty)) plotslist <- list() p_order <- c(3, 2, 4, 1, 6, 5) metrics_names <- c('Completion Time', 'Error Rate', 'Confidence', 'Easiness') titles <- list() titles[[1]] <- NULL i <- 2 for (metric in metrics_names) { t <- ggdraw() + draw_label(metric, x = 0.6, size = 20) titles[[i]] <- t i <- i + 1 } plotslist[[1]] <- cowplot::plot_grid(plotlist = titles, nrow = 1, rel_widths = c(2, 2, 2, 2, 2)) for(i in 1:6){ order <- p_order[[i]] p = paste0('p', order) grid <- list() ## ADD THE SIZE AS A COLUMN gt <- 1 size <- screen_size %>% filter(user==p) title <- paste0(p, ' (', size[1, 'width'], ',', size[1, 'height'], ')') t <- ggdraw() + draw_label(title) ## ADD ONE BARCHART PER measure data_p <- d %>% filter(user == p) # TIME time <- ggplot(data_p, aes(x=vis, y=mean_time)) + geom_bar(stat='identity', fill='dodgerblue2') + coord_cartesian(ylim=c(0,160)) # ERROR error <- ggplot(data_p, aes(x=vis, y=mean_error)) + geom_bar(stat='identity', fill='darkorange3') + coord_cartesian(ylim=c(0,100)) # CONF conf <- ggplot(data_p, aes(x=vis, y=mean_conf)) + geom_bar(stat='identity', fill='#FF6C90') + coord_cartesian(ylim=c(0,5)) # DIF dif <- ggplot(data_p, aes(x=vis, y=mean_conf)) + geom_bar(stat='identity', fill='#00BC59') + coord_cartesian(ylim=c(0,5)) ## ADD GRID AS NEW PLOT plotslist[[i+1]] <- cowplot::plot_grid(t, time, error, conf, dif, nrow = 1) } margin = theme(plot.margin = unit(c(2,2,2,2), "cm")) final_plot <- cowplot::plot_grid(plotlist = plotslist, nrow = 7, rel_heights = c(0.3, 2, 2, 2, 2, 2, 2)) filename <- paste0("plots/7_screen_size/screen_size", phase, ".pdf") ggsave(filename = filename, final_plot, device = "pdf", width=25, height=12) ######################################################################################################################################### ## TIME PER TASK tasks <- c('CO', 'CH', 'SI', 'MA') tasks_names <- c('Find relationships', 'Characterize relationships', 'Similar entities', 'Massive events') plots <- list() titles <- list() titles[[1]] <- NULL for (i in 1:4) { task <- tasks[[i]] task_name <- tasks_names[[i]] t <- ggdraw() + draw_label(task_name, x = 0.6) titles[[i+1]] <- t } plots[[1]] <- cowplot::plot_grid(plotlist = titles, nrow = 1) plots[[1]] d <- mydata %>% select(user, vis, mean_time, question_code) %>% group_by(user, vis, question_code) %>% summarise(mean_time = mean(mean_time)) #stats_tasks <- d %>% group_by(question_code) %>% # summarise(min_time = min(mean_time), # max_time = max(mean_time)) #min_test <- list('CO'=1, 'CH'=100, 'SI'=20, 'MA'=500) #max_test <- list('CO'=1, 'CH'=100, 'SI'=20, 'MA'=500) for(i in 1:6){ order <- p_order[[i]] p = paste0('p', order) grid <- list() ## ADD THE SIZE AS A COLUMN size <- screen_size %>% filter(user==p) title <- paste0(p, ' (', size[1, 'width'], ',', size[1, 'height'], ')') t <- ggdraw() + draw_label(title) grid[[1]] <- t for(j in 1:4){ data_p <- d %>% filter(user == p & question_code == tasks[[j]]) #stats_t <- stats_tasks %>% filter(question_code==tasks[[j]]) #data_p$min <- stats_t[1, 'min_time'] #data_p$max <- stats_t[1, 'max_time'] #min_t <- as.numeric(stats_t[1, 'min_time']) #min_t <- min_test[[tasks[[j]]]] #max_t <- as.numeric(stats_t[1, 'max_time']) grid[[j+1]] <- ggplot(data_p, aes(x=vis, y=mean_time)) + geom_bar(stat='identity', fill='dodgerblue2') + coord_cartesian(ylim=c(0,250)) #+ #geom_errorbar(aes(ymin=min_t, ymax=max_t), colour = "red", stat = "identity") } ## ADD GRID AS NEW PLOT plots[[i+1]] <- cowplot::plot_grid(plotlist = grid, nrow = 1) } margin = theme(plot.margin = unit(c(2,2,2,2), "cm")) final_plot <- cowplot::plot_grid(plotlist = plots, nrow = 7) filename <- paste0("plots/7_screen_size/screen_size_time", phase, ".pdf") ggsave(filename = filename, final_plot, device = "pdf", width=25, height=12) ########################################################################################################################################### ## ERROR PER TASK tasks <- c('CO', 'CH', 'SI', 'MA') tasks_names <- c('Find relationships', 'Characterize relationships', 'Similar entities', 'Massive events') plots <- list() titles <- list() titles[[1]] <- NULL for (i in 1:4) { task <- tasks[[i]] task_name <- tasks_names[[i]] t <- ggdraw() + draw_label(task_name, x = 0.6) titles[[i+1]] <- t } plots[[1]] <- cowplot::plot_grid(plotlist = titles, nrow = 1) plots[[1]] d <- mydata %>% select(user, vis, mean_error, question_code) %>% group_by(user, vis, question_code) %>% summarise(mean_error = mean(mean_error)) stats_tasks <- d %>% group_by(question_code) %>% summarise(min_error = min(mean_error), max_error = max(mean_error)) for(i in 1:6){ order <- p_order[[i]] p = paste0('p', order) grid <- list() ## ADD THE SIZE AS A COLUMN gt <- 1 size <- screen_size %>% filter(user==p) title <- paste0(p, ' (', size[1, 'width'], ',', size[1, 'height'], ')') t <- ggdraw() + draw_label(title) grid[[1]] <- t for(j in 1:4){ data_p <- d %>% filter(user == p & question_code == tasks[[j]]) #stats_t <- stats_tasks %>% filter(question_code==tasks[[j]]) #min_t <- as.numeric(stats_t[1, 'min_error']) #max_t <- as.numeric(stats_t[1, 'max_error']) grid[[j+1]] <-ggplot(data_p, aes(x=vis, y=mean_error)) + geom_bar(stat='identity', fill='darkorange3') + coord_cartesian(ylim=c(0,250)) #+ #geom_line() + #geom_linerange(aes(ymin=min_t, ymax=max_t), colour = "blue") } ## ADD GRID AS NEW PLOT plots[[i+1]] <- cowplot::plot_grid(plotlist = grid, nrow = 1) } margin = theme(plot.margin = unit(c(2,2,2,2), "cm")) final_plot <- cowplot::plot_grid(plotlist = plots, nrow = 7) filename <- paste0("plots/7_screen_size/screen_size_error", phase, ".pdf") ggsave(filename = filename, final_plot, device = "pdf", width=25, height=12)