#Munge
d = read.csv("KE1_A.csv")

d.long = d %>%
  gather(variable, value, contains("_")) %>%
  mutate(trial_num =  unlist(lapply(strsplit(as.character(variable),
                                      "_"),function(x) x[2])),
         variable = unlist(lapply(strsplit(as.character(variable),
                                      "_"),function(x) x[1]))) %>%
  spread(variable, value) %>%
  mutate(trial_num = as.numeric(trial_num),
         rating = as.numeric(rating),
         obj = as.factor(obj))

Number of participants by condition

d.long %>%
  group_by(subids) %>%
  slice(1) %>%
  ungroup () %>%
  count(condition) %>%
  kable()
condition n
building_difficulty 15
building_time 16
complexity 33
visual_complexity 16

Rating distributions by condition

#Distribution across all responses
ggplot(d.long, aes(x = rating, fill = condition)) +
  geom_histogram() +
  facet_wrap(~condition) +
  theme_bw()  +
  theme(legend.position = "none")

Lots of zero responses in building difficulty condition.

ggplot(d.long, aes(y = rating, x = condition, fill = condition)) +
  geom_boxplot() +
  theme_bw() +
  theme(legend.position = "none")

Image rating by condition

condition.ratings = d.long %>%
  group_by(condition, obj) %>%
  multi_boot_standard(column = "rating") %>%
  mutate(obj_lab = unlist(lapply(strsplit(as.character(obj),
                                      "_F"),function(x) x[1])),
         obj_lab = gsub('[[:punct:]]', '', obj_lab) )
condition.ratings %>%
  filter(condition == "building_difficulty") %>%
  arrange(mean) %>%
  mutate(obj_lab = fct_reorder(obj_lab, mean),
         obj = paste0("thumbnails/", obj),
         pic_height = rep(c(1 ,.95, .9),n()/3))  %>%
  ggplot(aes(x = obj_lab, y = mean)) +
  geom_bar(stat = "identity", fill = "#F8766D" ) + 
  geom_image(aes(image=obj, y = pic_height), size = .04, by = "width") +
  geom_linerange(aes(ymax=ci_upper, ymin=ci_lower)) +
  theme_bw() +
  xlab("Structure") +
  ylab("Mean Rating") +
  ggtitle("Building Difficulty") +
  ylim(0,1) +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 90, vjust = .3, hjust = 1))

condition.ratings %>%
  filter(condition == "building_time") %>%
  arrange(mean) %>%
  mutate(obj_lab = fct_reorder(obj_lab, mean),
         obj = paste0("thumbnails/", obj),
         pic_height = rep(c(1 ,.95, .9),n()/3))  %>%
  ggplot(aes(x = obj_lab, y = mean)) +
  geom_bar(stat = "identity", fill = "#7CAE00") + 
  geom_image(aes(image=obj, y = pic_height), size = .04, by = "width") +
  geom_linerange(aes(ymax=ci_upper, ymin=ci_lower)) +
  theme_bw() +
  xlab("Structure") +
  ylab("Mean Rating") +
  ggtitle("Building Time") +
  ylim(0,1) +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 90, vjust = .3, hjust = 1)) 

condition.ratings %>%
  filter(condition == "complexity") %>%
  arrange(mean) %>%
  mutate(obj_lab = fct_reorder(obj_lab, mean),    
         obj = paste0("thumbnails/", obj),
         pic_height = rep(c(1 ,.95, .9),n()/3))  %>%
  ggplot(aes(x = obj_lab, y = mean)) +
  geom_bar(stat = "identity",  fill = "#00BFC4") + 
  geom_image(aes(image=obj, y = pic_height), size = .04, by = "width") +
  geom_linerange(aes(ymax=ci_upper, ymin=ci_lower)) +
  theme_bw() +
  xlab("Structure") +
  ylab("Mean Rating") +
  ggtitle("Complexity") +
   ylim(0,1) +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 90, vjust = .3, hjust = 1))

condition.ratings %>%
  filter(condition == "visual_complexity") %>%
  arrange(mean) %>%
  mutate(obj_lab = fct_reorder(obj_lab, mean),
         obj = paste0("thumbnails/", obj),
         pic_height = rep(c(1 ,.95, .9),n()/3))  %>%
  ggplot(aes(x = obj_lab, y = mean) ) +
  geom_bar(stat = "identity",  fill = "#C77CFF") + 
  geom_image(aes(image=obj, y = pic_height), size = .04, by = "width") +
  geom_linerange(aes(ymax=ci_upper, ymin=ci_lower)) +
  theme_bw() +
  xlab("Structure") +
  ylab("Mean Rating") +
  ggtitle("Visual Complexity") +
  ylim(0,1) +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 90,
                                   vjust = .3, hjust = 1))

Correlation between measures

corrs = condition.ratings %>%
  select(-ci_lower, -ci_upper) %>%
  spread(condition, mean)
lm_plot <- function(data, mapping, ...){
  p <- ggplot(data = data, mapping = mapping) + 
    geom_point() + 
    geom_smooth(method=lm, fill="blue", color="blue", ...)
  p
}

ggpairs(select(corrs, -1,-2), lower = list(continuous = lm_plot))