---
title: "Icteridae Data Vis"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(knitr)
library(flexdashboard)
library(tidyverse)
library(plotly)
# Measurement data:
birds <- read.csv("birds_combined_v2.csv")
birds <- as.tibble(birds)
birds4 <- birds %>%
mutate(bill_W_to_D = bill_width/bill_depth, rel_tail = tail/length, rel_wing = wing_length/length, rel_tarsus = tarsus/length)
icteridae <- birds4 %>%
filter(Family == "Icteridae")
# Data for tree:
library(ape)
library(phytools)
library(phylocanvas)
library(phylobase)
emberizoid_phy <- read.nexus("~/Desktop/sptree_MCC.tre")
icteridae_phy <- extract.clade(emberizoid_phy, 1071)
```
Column
-------------------------------------
### Tree: Icteridae
```{r}
write.tree(icteridae_phy, "icteridae_newick.tre")
icteridfile <- "~/Desktop/icteridae_newick.tre"
tree <- load.tree(icteridfile)
icterus_mrca <- names(phylobase::MRCA(tree, c("Icterus_pustulatus", "Icterus_maculialatus")))
north_mrca <- names(phylobase::MRCA(tree, c("Nesopsar_nigerrimus", "Molothrus_ater")))
south_mrca <- names(phylobase::MRCA(tree, c("Amblycercus_holosericeus", "Psarocolius_cassini")))
phycanv <- phylocanvas(tree, width = 400)
icterus_names <- get.descendants(tree, icterus_mrca)
north_names <- get.descendants(tree, north_mrca)
south_names <- get.descendants(tree, south_mrca)
for (nodename in icterus_names) {
phycanv <- style_node(phycanv, nodeid = nodename, fillcolor="red")
}
for (nodename in north_names) {
phycanv <- style_node(phycanv, nodeid = nodename, fillcolor="lightgreen")
}
for (nodename in south_names) {
phycanv <- style_node(phycanv, nodeid = nodename, fillcolor="blue")
}
phycanv
```
Column {.tabset}
-------------------------------------
### Body size by bill D/W
```{r}
p1 <- ggplot(icteridae, aes(x = log(length), y = bill_W_to_D)) +
geom_point(aes(group = Genus_species, colour = clade), alpha = 0.5, size = 4) +
labs(title = "Bill width to depth ratio and body length in North American blackbirds", y = "W/D") +
theme(legend.position="bottom", legend.box = "vertical")
ggplotly(p1, width = 500, height = 500, tooltip = c("group", "colour"))
```
### Body size by relative tail length
```{r}
p2 <- ggplot(icteridae, aes(x = log(length), y = rel_tail)) +
geom_point(aes(group = Genus_species, colour = clade), alpha = 0.5, size = 4) +
labs(title = "Tail/body ratio and body length in North American blackbirds", y = "W/D") +
theme(legend.position="bottom", legend.box = "vertical")
ggplotly(p2, width = 500, height = 500, tooltip = c("group", "colour"))
```