Bottom triangle is taxonomic data; top triangle is language data.
WIKI_TAXONOMIC <- here("data/processed/animal_distances_wiki.csv")
wiki_taxonomic <- read_csv(WIKI_TAXONOMIC)
TAXONOMIC_PATH <- here("data/processed/animal_distances_taxonomic.csv")
taxonomic_data <- read_csv(TAXONOMIC_PATH) %>%
rename(word1 = animal1,
word2 = animal2) %>%
select(-sim_type)
LABELS <- c("shark", "swan", "flamingo", "pigeon", "crow", "elephant",
"mammoth", "sloth", "beaver", "gorilla", "bat", "rhino",
"zebra", "llama", "hippo", "killerwhale", "dolphin", "giraffe",
"sheep", "goat", "deer", "pig", "boar", "lion", "panther", "cheetah",
"skunk", "panda", "polarbear", "grizzly") %>% rev() # from SI fig s2
word_order <- data.frame(word1 = LABELS,
word2 = LABELS,
word_order1 = 1:length(LABELS),
word_order2 = 1:length(LABELS))
all_taxo <- full_join(wiki_taxonomic, taxonomic_data) %>%
mutate_if(is.numeric, scale) %>%
left_join(word_order %>% select(contains("1"))) %>%
left_join(word_order %>% select(contains("2"))) %>%
mutate(word1 = fct_relevel(word1, LABELS),
word2 = fct_relevel(word2, LABELS),
target_dist = case_when(word_order1 < word_order2 ~ language_similarity,
word_order1 > word_order2 ~ similarity,
TRUE ~ NA_real_))
ggplot(all_taxo, aes(x = word1, y = word2, fill = target_dist)) +
geom_tile() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
scale_fill_viridis()
Bottom triangle is human data; top triangle is language data.
get_full_df <- function(df){
df %>%
rename(temp1 = animal1,
temp2 = animal2) %>%
mutate( animal1 = temp2,
animal2 = temp1) %>%
select(-contains("temp")) %>%
bind_rows(df) %>%
select(animal1, animal2, human_similarity)
}
# language data
LANG_ANIMAL_DISTANCE_COLOR <- here("data/processed/animal_color_distances_language_wiki.csv")
color_language_distances <- read_csv(LANG_ANIMAL_DISTANCE_COLOR)%>%
filter(animal1 != animal2)
language_color_mat <- color_language_distances %>%
spread(animal2, language_similarity_simple_dist_color) %>%
column_to_rownames("animal1") %>%
as.matrix() %>%
dist() %>%
hclust()
# human data
TIDY_HUMAN_PATH <- here("data/processed/tidy_human_data.csv")
human_distances <- read_csv(TIDY_HUMAN_PATH)
color_sighted <- human_distances %>%
filter(participant_type == "sighted",
similarity_type == "human_similarity_color") %>%
select(contains("animal"), human_similarity)
color_sighted_full <- get_full_df(color_sighted)
color_sighted_mat <- color_sighted_full %>%
spread(animal2, human_similarity) %>%
column_to_rownames("animal1") %>%
as.matrix()
rownames(color_sighted_mat) <- colnames(color_sighted_mat)
color_sighted_mat <- color_sighted_mat %>%
dist() %>%
hclust()
# get label order
label_in_order <- as.dendrogram(color_sighted_mat) %>% labels()
untangled_labels <- dendlist(as.dendrogram(color_sighted_mat),
as.dendrogram(language_color_mat)) %>%
untangle(method = "step2side")
label_in_order <- labels(untangled_labels[1][[1]])
animal_order <- data.frame(animal1 = label_in_order,
animal2 = label_in_order,
word_order1 = 1:length(label_in_order),
word_order2 = 1:length(label_in_order))
all_color_sighted <- full_join(color_sighted_full, color_language_distances) %>%
# mutate_if(is.numeric, scale) %>%
left_join(animal_order %>% select(contains("1"))) %>%
left_join(animal_order %>% select(contains("2"))) %>%
mutate(animal1 = fct_relevel(animal1, label_in_order),
animal2 = fct_relevel(animal2, label_in_order),
triangle = case_when(word_order1 < word_order2 ~ "top",
word_order1 > word_order2 ~ "bottom",
TRUE ~ NA_character_),
target_dist = case_when(triangle == "top" ~ language_similarity_simple_dist_color,
triangle == "bottom" ~ human_similarity,
TRUE ~ NA_real_)) %>%
group_by(triangle) %>%
mutate(target_dist = scale(target_dist))
ggplot(all_color_sighted, aes(x = animal1, y = animal2, fill = target_dist)) +
geom_tile() +
scale_fill_viridis() +
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
color_blind <- human_distances %>%
filter(participant_type == "blind",
similarity_type == "human_similarity_color") %>%
select(contains("animal"), human_similarity)
color_blind_full <- get_full_df(color_blind)
color_blind_full_mat <- color_blind_full %>%
spread(animal2, human_similarity) %>%
column_to_rownames("animal1") %>%
as.matrix()
rownames(color_blind_full_mat) <- colnames(color_blind_full_mat)
color_blind_full_mat <- color_blind_full_mat %>%
dist() %>%
hclust()
label_in_order <- as.dendrogram(color_blind_full_mat) %>% labels()
untangled_labels <- dendlist(as.dendrogram(color_blind_full_mat),
as.dendrogram(language_color_mat)) %>%
untangle(method = "step2side")
label_in_order <- labels(untangled_labels[1][[1]])
animal_order <- data.frame(animal1 = label_in_order,
animal2 = label_in_order,
word_order1 = 1:length(label_in_order),
word_order2 = 1:length(label_in_order))
all_color_blind <- full_join(color_blind_full,
color_language_distances) %>%
mutate_if(is.numeric, scale) %>%
left_join(animal_order %>% select(contains("1"))) %>%
left_join(animal_order %>% select(contains("2"))) %>%
mutate(animal1 = fct_relevel(animal1, label_in_order),
animal2 = fct_relevel(animal2, label_in_order),
target_dist = case_when(word_order1 < word_order2 ~ language_similarity_simple_dist_color,
word_order1 > word_order2 ~ human_similarity,
TRUE ~ NA_real_))
ggplot(all_color_blind, aes(x = animal1, y = animal2, fill = target_dist)) +
geom_tile() +
scale_fill_viridis() +
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
LANG_ANIMAL_DISTANCE_SHAPE <- here("data/processed/animal_shape_distances_language_wiki.csv")
shape_language_distances <- read_csv(LANG_ANIMAL_DISTANCE_SHAPE)%>%
filter(animal1 != animal2)
language_shape_mat <- shape_language_distances %>%
spread(animal2, language_similarity_simple_dist_shape) %>%
column_to_rownames("animal1") %>%
as.matrix() %>%
dist() %>%
hclust()
shape_sighted <- human_distances %>%
filter(participant_type == "sighted",
similarity_type == "human_similarity_shape") %>%
select(contains("animal"), human_similarity)
shape_sighted_full <- get_full_df(shape_sighted)
shape_sighted_mat <- shape_sighted_full %>%
spread(animal2, human_similarity) %>%
column_to_rownames("animal1") %>%
as.matrix()
rownames(shape_sighted_mat) <- colnames(shape_sighted_mat)
shape_sighted_mat <- shape_sighted_mat %>%
dist() %>%
hclust()
# get label order
label_in_order <- as.dendrogram(shape_sighted_mat) %>% labels()
untangled_labels <- dendlist(as.dendrogram(shape_sighted_mat),
as.dendrogram(language_shape_mat)) %>%
untangle(method = "step2side")
label_in_order <- labels(untangled_labels[1][[1]])
animal_order <- data.frame(animal1 = label_in_order,
animal2 = label_in_order,
word_order1 = 1:length(label_in_order),
word_order2 = 1:length(label_in_order))
all_shape_sighted <- full_join(shape_sighted_full, shape_language_distances) %>%
# mutate_if(is.numeric, scale) %>%
left_join(animal_order %>% select(contains("1"))) %>%
left_join(animal_order %>% select(contains("2"))) %>%
mutate(animal1 = fct_relevel(animal1, label_in_order),
animal2 = fct_relevel(animal2, label_in_order),
triangle = case_when(word_order1 < word_order2 ~ "top",
word_order1 > word_order2 ~ "bottom",
TRUE ~ NA_character_),
target_dist = case_when(triangle == "top" ~ language_similarity_simple_dist_shape,
triangle == "bottom" ~ human_similarity,
TRUE ~ NA_real_)) %>%
group_by(triangle) %>%
mutate(target_dist = scale(target_dist))
ggplot(all_shape_sighted, aes(x = animal1, y = animal2, fill = target_dist)) +
geom_tile() +
scale_fill_viridis() +
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
shape_blind <- human_distances %>%
filter(participant_type == "blind",
similarity_type == "human_similarity_shape") %>%
select(contains("animal"), human_similarity)
shape_blind_full <- get_full_df(shape_blind)
shape_blind_full_mat <- shape_blind_full %>%
spread(animal2, human_similarity) %>%
column_to_rownames("animal1") %>%
as.matrix()
rownames(shape_blind_full_mat) <- colnames(shape_blind_full_mat)
shape_blind_full_mat <- shape_blind_full_mat %>%
dist() %>%
hclust()
label_in_order <- as.dendrogram(shape_blind_full_mat) %>% labels()
untangled_labels <- dendlist(as.dendrogram(shape_blind_full_mat),
as.dendrogram(language_shape_mat)) %>%
untangle(method = "step2side")
label_in_order <- labels(untangled_labels[1][[1]])
animal_order <- data.frame(animal1 = label_in_order,
animal2 = label_in_order,
word_order1 = 1:length(label_in_order),
word_order2 = 1:length(label_in_order))
all_shape_blind <- full_join(shape_blind_full,
shape_language_distances) %>%
mutate_if(is.numeric, scale) %>%
left_join(animal_order %>% select(contains("1"))) %>%
left_join(animal_order %>% select(contains("2"))) %>%
# group_by(animal1) %>%
# mutate(human_similarity = human_similarity/sum(human_similarity),
# language_similarity_simple_dist_shape = language_similarity_simple_dist_shape/sum(language_similarity_simple_dist_shape)) %>%
# ungroup()%>%
mutate(animal1 = fct_relevel(animal1, label_in_order),
animal2 = fct_relevel(animal2, label_in_order),
target_dist = case_when(word_order1 < word_order2 ~ language_similarity_simple_dist_shape,
word_order1 > word_order2 ~ human_similarity,
TRUE ~ NA_real_))
ggplot(all_shape_blind, aes(x = animal1, y = animal2, fill = target_dist)) +
geom_tile() +
scale_fill_viridis() +
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
LANG_ANIMAL_DISTANCE_TEXTURE <- here("data/processed/animal_texture_distances_language_wiki.csv")
texture_language_distances <- read_csv(LANG_ANIMAL_DISTANCE_TEXTURE)%>%
filter(animal1 != animal2)
language_texture_mat <- texture_language_distances %>%
spread(animal2, language_similarity_simple_dist_texture) %>%
column_to_rownames("animal1") %>%
as.matrix() %>%
dist() %>%
hclust()
texture_sighted <- human_distances %>%
filter(participant_type == "sighted",
similarity_type == "human_similarity_skin") %>%
select(contains("animal"), human_similarity)
texture_sighted_full <- get_full_df(texture_sighted)
texture_sighted_mat <- texture_sighted_full %>%
spread(animal2, human_similarity) %>%
column_to_rownames("animal1") %>%
as.matrix()
rownames(texture_sighted_mat) <- colnames(texture_sighted_mat)
texture_sighted_mat <- texture_sighted_mat %>%
dist() %>%
hclust()
# get label order
label_in_order <- as.dendrogram(texture_sighted_mat) %>% labels()
untangled_labels <- dendlist(as.dendrogram(texture_sighted_mat),
as.dendrogram(language_texture_mat)) %>%
untangle(method = "step2side")
label_in_order <- labels(untangled_labels[1][[1]])
animal_order <- data.frame(animal1 = label_in_order,
animal2 = label_in_order,
word_order1 = 1:length(label_in_order),
word_order2 = 1:length(label_in_order))
all_texture_sighted <- full_join(texture_sighted_full, texture_language_distances) %>%
# mutate_if(is.numeric, scale) %>%
left_join(animal_order %>% select(contains("1"))) %>%
left_join(animal_order %>% select(contains("2"))) %>%
mutate(animal1 = fct_relevel(animal1, label_in_order),
animal2 = fct_relevel(animal2, label_in_order),
triangle = case_when(word_order1 < word_order2 ~ "top",
word_order1 > word_order2 ~ "bottom",
TRUE ~ NA_character_),
target_dist = case_when(triangle == "top" ~ language_similarity_simple_dist_texture,
triangle == "bottom" ~ human_similarity,
TRUE ~ NA_real_)) %>%
group_by(triangle) %>%
mutate(target_dist = scale(target_dist))
ggplot(all_texture_sighted, aes(x = animal1, y = animal2, fill = target_dist)) +
geom_tile() +
scale_fill_viridis() +
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
texture_blind <- human_distances %>%
filter(participant_type == "blind",
similarity_type == "human_similarity_skin") %>%
select(contains("animal"), human_similarity)
texture_blind_full <- get_full_df(texture_blind)
texture_blind_full_mat <- texture_blind_full %>%
spread(animal2, human_similarity) %>%
column_to_rownames("animal1") %>%
as.matrix()
rownames(texture_blind_full_mat) <- colnames(texture_blind_full_mat)
texture_blind_full_mat <- texture_blind_full_mat %>%
dist() %>%
hclust()
label_in_order <- as.dendrogram(texture_blind_full_mat) %>% labels()
untangled_labels <- dendlist(as.dendrogram(texture_blind_full_mat),
as.dendrogram(language_texture_mat)) %>%
untangle(method = "step2side")
label_in_order <- labels(untangled_labels[1][[1]])
animal_order <- data.frame(animal1 = label_in_order,
animal2 = label_in_order,
word_order1 = 1:length(label_in_order),
word_order2 = 1:length(label_in_order))
all_texture_blind <- full_join(texture_blind_full,
texture_language_distances) %>%
mutate_if(is.numeric, scale) %>%
left_join(animal_order %>% select(contains("1"))) %>%
left_join(animal_order %>% select(contains("2"))) %>%
mutate(animal1 = fct_relevel(animal1, label_in_order),
animal2 = fct_relevel(animal2, label_in_order),
target_dist = case_when(word_order1 < word_order2 ~ language_similarity_simple_dist_texture,
word_order1 > word_order2 ~ human_similarity,
TRUE ~ NA_real_))
ggplot(all_texture_blind, aes(x = animal1, y = animal2, fill = target_dist)) +
geom_tile() +
scale_fill_viridis() +
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))