File size: 7,462 Bytes
2f8aa81 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
#heat map with a tree plot: boundness + informativity
source("set_up_inla.R")
metrics_joined <- metrics_joined %>%
filter(!is.na(L1_log10_st)) %>%
rename(L1_log_st = L1_log10_st) %>%
mutate(L1_copy = L1_log_st) %>%
filter(!is.na(L2_prop)) %>%
dplyr::mutate(L2_prop = scale(L2_prop)[, 1]) %>%
mutate(L2_copy = L2_prop) %>%
filter(!is.na(neighboring_languages_st)) %>%
filter(!is.na(Official)) %>%
filter(!is.na(Education)) %>%
filter(!is.na(boundness_st)) %>%
filter(!is.na(informativity_st))
#dropping tips not in Grambank
metrics_joined <-
metrics_joined[metrics_joined$Language_ID %in% tree$tip.label,]
tree <- keep.tip(tree, metrics_joined$Language_ID)
x <-
assert_that(all(tree$tip.label %in% metrics_joined$Language_ID), msg = "The data and phylogeny taxa do not match")
metrics_joined <-
metrics_joined %>% mutate(Language_ID_2 = Language_ID) %>% column_to_rownames(var = "Language_ID_2")
df1 <-
metrics_joined %>% dplyr::select(boundness_st) %>% rename(boundness = boundness_st)
df2 <-
metrics_joined %>% dplyr::select(informativity_st) %>% rename(informativity = informativity_st)
### Adding colored branches of the biggest families in the dataset
metrics_joined %>%
group_by(Family_ID) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n)) %>%
arrange(desc(n)) %>%
filter(!Family_ID == "") %>%
top_n(12, freq) -> table
biggest_families <- table$Family_ID
metrics_joined$family_status <- NA
metrics_joined$family_status <-
ifelse(metrics_joined$Family_ID %in% biggest_families,
metrics_joined$Family_ID,
"other")
#double-checking if all families indeed converted to names and none is left with "NA"
unique(metrics_joined$family_status)
metrics_joined <- metrics_joined %>%
mutate(
family =
dplyr::recode(
family_status,
"aust1307" = "Austronesian",
"aust1305" = "Austroasiatic",
"indo1319" = "Indo-European",
"atla1278" = "Atlantic-Congo",
"utoa1244" = "Uto-Aztecan",
"sino1245" = "Sino-Tibetan",
"afro1255" = "Afro-Asiatic",
"nucl1709" = "Nuclear Trans New Guinea",
"maya1287" = "Mayan",
"pano1259" = "Pano-Tacanan",
"otom1299" = "Otomanguean",
"chib1249" = "Chibchan ",
"nakh1245" = "Nakh-Daghestanian",
"cent2225" = "Central Sudanic",
"drav1251" = "Dravidian",
"ural1272" = "Uralic",
"pama1250" = "Pama-Nyungan",
"other" = "other"
)
)
#double-checking if all families indeed converted to names and none is left with "NA"
unique(metrics_joined$family)
#ordering the families in the desired way
#metrics_joined$family <- factor(metrics_joined$family, order = TRUE, levels = c("other", "Austronesian", "Austroasiatic", "Sino-Tibetan", "Indo-European", "Atlantic-Congo", "Afro-Asiatic", "Uto-Aztecan", "Nuclear Trans New Guinea"))
tips_lists <- vector(mode = "list", length = 12)
for (f in 1:length(biggest_families)) {
tips_lists[[f]] <-
metrics_joined[metrics_joined$Family_ID == biggest_families[f], ]$Language_ID
tips_lists[[f]] <- na.omit(tips_lists[[f]])
}
#the correct order within biggest families is preserved and the Glottocodes are replaced with suitable family name labels
biggest_families_verbose <- dplyr::recode(
biggest_families,
"aust1307" = "Austronesian",
"aust1305" = "Austroasiatic",
"indo1319" = "Indo-European",
"atla1278" = "Atlantic-Congo",
"utoa1244" = "Uto-Aztecan",
"sino1245" = "Sino-Tibetan",
"afro1255" = "Afro-Asiatic",
"nucl1709" = "Nuclear Trans New Guinea",
"maya1287" = "Mayan",
"pano1259" = "Pano-Tacanan",
"otom1299" = "Otomanguean",
"chib1249" = "Chibchan ",
"nakh1245" = "Nakh-Daghestanian",
"cent2225" = "Central Sudanic",
"drav1251" = "Dravidian",
"ural1272" = "Uralic",
"pama1250" = "Pama-Nyungan",
"other" = "other"
)
names(tips_lists) <- biggest_families_verbose
nodes <- vector(mode = "character", length = length(biggest_families))
for (tips in 1:length(tips_lists)) {
nodes[tips] <- getMRCA(tree, tips_lists[[tips]])
}
#test
#nodes <- vector(mode="character", length=1)
#nodes[1] <- getMRCA(tree, tips_lists[[4]])
nodes <- as.numeric(nodes)
coloured_branches <- groupClade(tree, nodes)
coloured_branches <-
ggtree(
coloured_branches,
layout = 'rect',
branch.length = 'none',
size = 0.5
)
p1 <-
gheatmap(
coloured_branches,
df1,
offset = -1,
width = .1,
colnames_angle = 0,
colnames_offset_y = 25,
colnames_position = "top",
colnames = F,
#removing column names
font.size = 20,
hjust = 0.5,
color = FALSE
) + ylim(-5, 1480) + #ylim(-5, 1450)
scale_fill_viridis_c(option = "magma", direction = -1) + labs(fill = "fusion") + theme(legend.position = "bottom",
legend.key.size = unit(1.4, 'cm')) +
geom_cladelabel(
node = nodes[1],
label = biggest_families_verbose[1],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[2],
label = biggest_families_verbose[2],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[3],
label = biggest_families_verbose[3],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[4],
label = biggest_families_verbose[4],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[5],
label = biggest_families_verbose[5],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[6],
label = biggest_families_verbose[6],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[7],
label = biggest_families_verbose[7],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[8],
label = biggest_families_verbose[8],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[9],
label = biggest_families_verbose[9],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[10],
label = biggest_families_verbose[10],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[11],
label = biggest_families_verbose[11],
offset = 6,
align = TRUE,
fontsize = 13
) +
geom_cladelabel(
node = nodes[12],
label = biggest_families_verbose[12],
offset = 6,
align = TRUE,
fontsize = 13
) + labs(fill = "fusion")
p2 <- p1 + new_scale_fill()
p3 <- gheatmap(
p2,
df2,
offset = 2,
width = .1,
colnames_angle = 0,
colnames_offset_y = 25,
colnames_position = "top",
font.size = 20,
hjust = 0.5,
color = FALSE,
colnames = FALSE
) + ylim(-5, 1400) +
xlim(-1, 55) +
scale_fill_viridis_c(option = "viridis", direction = -1) +
labs(fill = "informativity") +
theme(
legend.box = "horizontal",
legend.position = "bottom",
text = element_text(size = 55),
legend.key.size = unit(1.6, 'cm')
)
p3
ggsave(
file = "output/plot_heatmap_B_I.svg",
plot = p3,
width = 25,
height = 27,
dpi = 600
)
ggsave(
file = "output/plot_heatmap_B_I.pdf",
plot = p3,
width = 25,
height = 27,
dpi = 600
)
ggsave(
file = "output/plot_heatmap_B_I.jpeg",
plot = p3,
width = 25,
height = 27,
dpi = 600
)
|