library(plyr) library(tidyverse) library(gridExtra) library(cowplot) library(data.table) #install.packages("extrafont") #library(extrafont) # Install **TTF** Latin Modern Roman fonts from www.fontsquirrel.com/fonts/latin-modern-roman # Import the newly installed LModern fonts, change the pattern according to the # filename of the lmodern ttf files in your fonts folder #font_import(pattern = 'lmroman*') 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) if (exists ("mydata")) { rm(mydata) } mydata <- read.table("aggregated_data.csv", 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('Scope', 'Direction', 'Arrival', 'Hops', 'Peaks') plots <- list() for (i in 1:5) { task <- tasks[i] task_name <- tasks_names[i] # READ TIME filename_time <- paste0('plots/printed_time_means_task_', task, '.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('plots/printed_time_diffs_task_', task, '.txt', sep='') printed_timediff <- read.table(filename_timediff, header = T, sep = ',') printed_timediff$technique <- factor(printed_timediff$technique, levels=c("Gly-Ani","Gly-SMul","Ani-SMul")) # READ ERROR filename_error <- paste0('plots/printed_error_means_task_', task, '.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('plots/printed_error_diffs_task_', task, '.txt', sep='') printed_errordiff <- read.table(filename_errordiff, header = T, sep = ',') printed_errordiff$technique <- factor(printed_errordiff$technique, levels=c("Gly-Ani","Gly-SMul","Ani-SMul")) # 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 = 40, "", "", 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 = -15, ymax = 25, "", "", 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 = -15, ymax = 15, "", "", mycolor='darkorange3') #### CONFIDENCE # 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_confidence") tmp <- tmp [myvars] tmp2 <- reshape(tmp, timevar="vis", idvar=c("user","question_code","question_internal_id"), direction="wide") colnames(tmp2) <- gsub("mean_confidence.", "", colnames(tmp2)) tmp2 <- na.omit(tmp2) setnames(tmp2, old=c("SmallMultiples","Animation", "OneMap"), new=c("SMul","Ani", "Gly")) likert_table <- tmp2 myvars <- c("SMul", "Ani","Gly") # Symbol name has been changed in paper to Glyph likert_table <- likert_table[myvars] likert_table$SMul = factor (likert_table$SMul, levels = c("1","2","3"), ordered = TRUE) likert_table$Ani = factor (likert_table$Ani, levels = c("1","2","3"), ordered = TRUE) likert_table$Gly = factor (likert_table$Gly, levels = c("1","2","3"), ordered = TRUE) library(psych) headTail(likert_table) str(likert_table) library(likert) Result <- likert(likert_table) summary(Result) confidence_plot <- plot(Result, type="bar", group.order=c("SMul", "Ani", "Gly")) + theme(legend.position = 'none', axis.title.x = element_blank(), plot.background = element_blank(), panel.background = element_blank(), text = element_text(size = 20, 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")), # confidence plot_grid(confidence_plot, ncol = 1) + theme(plot.background = element_rect(color = "#999999")), # config #nrow = 3, #rel_heights =c(1, 5, 5) ncol = 4, rel_widths =c(1, 5, 5, 3) ) plots[[i]] <- this_grid } margin = theme(plot.margin = unit(c(2,2,2,2), "cm")) #p <- do.call("grid.arrange", c(plots, ncol=3)) p <- do.call("plot_grid", c(plots, nrow=5)) #p <- do.call("ggarrange", c(plots, ncol=6)) #ggarrange(plot_time, plot_timediff, plot_error, plot_errordiff, ncol = 2, nrow = 2) filename <- "plots/table_all.pdf" ggsave(filename = filename, p, device = "pdf", width=25, height=12) #grid.arrange(grobs = lapply(pl, "+", margin))