library(plyr) library(tidyverse) library(gridExtra) library(cowplot) library(data.table) library(extrafont) loadfonts(device = "win") par(family = "LM Roman 10") #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' file_data <- paste0("aggregated_data", phase,".csv") if (exists ("mydata")) { rm(mydata) } mydata <- read.table(file_data, header=T, sep=",") # collect all trials in order to calculate average error rate and time per question per participant, keep non training trials (isTraining = "False") tmp <- mydata tmp <- tmp [ order(tmp$user, tmp$vis), ] # ALL TASKS tasks <- c('A', 'B', 'C', 'D', 'E') tasks_names <- c('Base Locations', 'Base Time', 'Distance', 'Direction', 'Adjacency') plots <- list() i = 3 theme_set(theme_gray(base_size = 12)) for (i in 1:5) { task <- tasks[i] task_name <- tasks_names[i] ##### MAIN path <- 'plots/per_task/raw' # READ TIME filename_time <- paste0(path, '/printed_time_means_task_', task, phase,'.txt', sep='') printed_time <- read.table(filename_time, header = T, sep = ',') colnames(printed_time)[colnames(printed_time)=="upperBound_CI."] <- "upperBound_CI" #printed_time$vis <- factor(printed_time$vis, levels=rev(levels(printed_time$vis))) filename_timediff <- paste0(path, '/printed_time_diffs_task_', task, phase, '.txt', sep='') printed_timediff <- read.table(filename_timediff, header = T, sep = ',') #printed_timediff$technique <- factor(printed_timediff$technique, levels=c("PAOH-NSL")) # READ ERROR filename_error <- paste0(path, '/printed_error_means_task_', task, phase, '.txt', sep='') printed_error <- read.table(filename_error, header = T, sep = ',') colnames(printed_error)[colnames(printed_error)=="upperBound_CI."] <- "upperBound_CI" #printed_error$vis <- factor(printed_error$vis, levels=rev(levels(printed_error$vis))) filename_errordiff <- paste0(path, '/printed_error_diffs_task_', task, phase, '.txt', sep='') printed_errordiff <- read.table(filename_errordiff, header = T, sep = ',') #printed_errordiff$technique <- factor(printed_errordiff$technique, levels=c("PAOH-NSL")) # PLOT LABEL df_label <- data.frame( x = c(0), y = c(0), text = c(task_name) ) plot_label <- ggplot(df_label, aes(x, y)) + geom_text(aes(label = text), size=7) + ylim(0, 0) + theme_void() # PLOT TIME analysisData <- c() analysisData$name <- printed_time$vis analysisData$pointEstimate <- printed_time$mean_time analysisData$ci.max <- printed_time$upperBound_CI analysisData$ci.min <- printed_time$lowerBound_CI plot_time <- barChart(printed_time, analysisData$name, nbTechs = 3, ymin = 0, ymax = 70, "", "", mycolor='dodgerblue2') ## TIME DIFF analysisData <- c() analysisData$name <- printed_timediff$technique analysisData$pointEstimate <- printed_timediff$mean_time analysisData$ci.max <- printed_timediff$upperBound_CI analysisData$ci.min <- printed_timediff$lowerBound_CI analysisData$level <- printed_timediff$corrected_CI analysisData$ci_corr.max <- printed_timediff$upperBound_CI_corr analysisData$ci_corr.min <- printed_timediff$lowerBound_CI_corr plot_timediff <- barChart(printed_timediff, analysisData$name, nbTechs = 3, ymin = -40, ymax = 35, "", "", mycolor='dodgerblue2') # PLOT ERROR analysisData <- c() analysisData$name <- printed_error$vis analysisData$pointEstimate <- printed_error$mean_time analysisData$ci.max <- printed_error$upperBound_CI analysisData$ci.min <- printed_error$lowerBound_CI plot_error <- barChart(printed_error, analysisData$name, nbTechs = 3, ymin = 0, ymax = 15, "", "", mycolor='darkorange3') ## ERROR DIFF analysisData <- c() analysisData$name <- printed_errordiff$technique analysisData$pointEstimate <- printed_errordiff$mean_time analysisData$ci.max <- printed_errordiff$upperBound_CI analysisData$ci.min <- printed_errordiff$lowerBound_CI analysisData$level <- printed_errordiff$corrected_CI analysisData$ci_corr.max <- printed_errordiff$upperBound_CI_corr analysisData$ci_corr.min <- printed_errordiff$lowerBound_CI_corr plot_errordiff <- barChart(printed_errordiff, analysisData$name, nbTechs = 3, ymin = -20, ymax = 20, "", "", mycolor='darkorange3') #### DIFFICULTY # TODO: MAKE IT PRETTY tmp <- mydata[ which (mydata$question_code == task),] tmp <- tmp [ order(tmp$user, tmp$vis), ] # myvars <- c("user", "vis", "question_code","question_internal_id","mean_difficulty") tmp <- tmp [myvars] tmp2 <- reshape(tmp, timevar="vis", idvar=c("user","question_code","question_internal_id"), direction="wide") colnames(tmp2) <- gsub("mean_difficulty.", "", colnames(tmp2)) tmp2 <- na.omit(tmp2) likert_table <- tmp2 myvars <- c("CoordV","GlyMa", "LocSto") likert_table <- likert_table[myvars] likert_table$CoordV = factor (likert_table$CoordV, levels = c("1","2","3","4","5"), ordered = TRUE) likert_table$GlyMa = factor (likert_table$GlyMa, levels = c("1","2","3","4","5"), ordered = TRUE) likert_table$LocSto = factor (likert_table$LocSto, levels = c("1","2","3","4","5"), ordered = TRUE) likert_table = rename(likert_table, MapG = GlyMa) likert_table = rename(likert_table, TimeG = LocSto) library(psych) headTail(likert_table) str(likert_table) library(likert) Result <- likert(likert_table) summary(Result) difficulty_plot <- plot(Result, type="bar", group.order=c("MapG", "CoordV", "TimeG"), text.size = 6) + theme(legend.position = 'none', axis.title.x = element_blank(), plot.background = element_blank(), panel.background = element_blank(), text = element_text(size = 18, color = 'black'), axis.text = element_text(size = 18, color = 'black'), strip.text = element_text(size = 18, color = 'black'), legend.text = element_text(size = 18, color = 'black')) + ggtitle('') # make grids this_grid <- plot_grid( # label plot_grid(plot_label, ncol = 1), # + theme(plot.background = element_rect(color = "black")), # time plot_grid(plot_time, plot_timediff, ncol = 2, rel_widths =c(2, 3)) + theme(plot.background = element_rect(color = "#999999")), # error plot_grid(plot_error, plot_errordiff, ncol = 2, rel_widths =c(2, 3)) + theme(plot.background = element_rect(color = "#999999")), # difficulty plot_grid(difficulty_plot, ncol = 1) + theme(plot.background = element_rect(color = "#999999")), # config #nrow = 3, #rel_heights =c(1, 5, 5) ncol = 5, rel_widths =c(1, 8, 8, 4) ) plots[[i]] <- this_grid } margin = theme(plot.margin = unit(c(2,2,2,2), "cm")) p <- do.call("plot_grid", c(plots, nrow=6)) filename <- paste0("plots/per_task/all_metrics_per_task_phase", phase, ".pdf") ggsave(filename = filename, p, device = "pdf", width=25, height=12)