Column

Data from Barker et al (2015) New insights into New World biogeography: An integrated view from the phylogeny of blackbirds, cardinals, sparrows, tanagers, warblers, and allies. The Auk, 132(2), pp.333-348.

Column

Body size by bill W/D

Body size by relative tail length

Body size by relative wing length

Body size by relative tarsus length

---
title: "Body size and shape in New World blackbirds (Icteridae)"
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 <- as.tibble(read.csv("birds_combined_v2.csv"))

birds <- birds %>% 
  mutate(bill_W_to_D = bill_width/bill_depth, rel_tail = tail/length, rel_wing = wing_length/length, rel_tarsus = tarsus/length)

icteridae_data <- birds %>%
  filter(Family == "Icteridae") 

```



```{r}

# 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)

```



```{r}

# Include only overlapping species:

icteridae_phy_pruned <- drop.tip(icteridae_phy, icteridae_phy$tip.label[-na.omit(match(icteridae_data$Genus_species, icteridae_phy$tip.label))])

#plotTree(icteridae_phy_pruned)

taxa <- icteridae_phy_pruned$tip.label

#length(taxa)

icteridae_data_pruned <- icteridae_data %>% 
     filter(Genus_species %in% taxa)

#length(icteridae_data_pruned$Genus_species)

```

Column 
-------------------------------------
    
### Data from Barker et al (2015) New insights into New World biogeography: An integrated view from the phylogeny of blackbirds, cardinals, sparrows, tanagers, warblers, and allies. The Auk, 132(2), pp.333-348.

```{r}

write.tree(icteridae_phy_pruned, "icteridae_newick.tre")

icteridfile <- "~/Desktop/icteridae_newick.tre"
tree <- load.tree(icteridfile)

#plotTree(icteridae_phy_pruned)

icterus_mrca <- names(phylobase::MRCA(tree, c("Icterus_pustulatus", "Icterus_icterus")))
north_mrca <- names(phylobase::MRCA(tree, c("Agelaius_tricolor", "Molothrus_ater")))
south_mrca <- names(phylobase::MRCA(tree, c("Cacicus_melanicterus", "Psarocolius_montezuma")))

phycanv <- phylocanvas(tree, treetype = "radial", width = 500, nodesize = 30)
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, nodesizeratio = 0.5, fillcolor = "white", labelcolor="red")
}
for (nodename in north_names) {
  phycanv <- style_node(phycanv, nodeid = nodename, nodesizeratio = 0.5, fillcolor = "white", labelcolor="mediumblue")
}
for (nodename in south_names) {
  phycanv <- style_node(phycanv, nodeid = nodename, nodesizeratio = 0.5, fillcolor = "white", labelcolor="gold")
}

phycanv

```

Column {.tabset}
-------------------------------------
   
### Body size by bill W/D

```{r}

(p1 <- ggplot(icteridae_data_pruned, aes(x = length, y = bill_W_to_D)) +
  geom_point(aes(group = Genus_species, colour = clade), alpha = 0.6, size = 3) + 
  scale_color_manual(values = c("red", "mediumblue", "gold")) + 
  labs(y = "W/D", caption = "Data from Harmon et al (2010) \nEarly bursts of body size and shape evolution \nare rare in comparative data. Evolution 64: 2385–2396.") +
  ggtitle("Bill width to depth ratio versus body length\nin 50 blackbird species") +
  theme(legend.position="bottom", legend.box = "vertical") + 
  theme_bw())

```
   
### Body size by relative tail length

```{r}

(p2 <- ggplot(icteridae_data_pruned, aes(x = length, y = rel_tail)) + 
  geom_point(aes(group = Genus_species, colour = clade), alpha = 0.6, size = 3) + 
  scale_color_manual(values = c("red", "mediumblue", "gold")) + 
  labs(y = "W/D", caption = "Data from Harmon et al (2010) \nEarly bursts of body size and shape evolution \nare rare in comparative data. Evolution 64: 2385–2396.") + 
  ggtitle("Tail/body ratio versus body length\nin 50 blackbird species") + 
  theme(legend.position="bottom", legend.box = "vertical") + 
  theme_bw())

```

### Body size by relative wing length

```{r}

(p3 <- ggplot(icteridae_data_pruned, aes(x = length, y = rel_wing)) + 
  geom_point(aes(group = Genus_species, colour = clade), alpha = 0.6, size = 3) + 
  scale_color_manual(values = c("red", "mediumblue", "gold")) + 
  labs(y = "W/D", caption = "Data from Harmon et al (2010) \nEarly bursts of body size and shape evolution \nare rare in comparative data. Evolution 64: 2385–2396.") + 
  ggtitle("Wing/body ratio versus body length\nin 50 blackbird species") + 
  theme(legend.position="bottom", legend.box = "vertical") + 
  theme_bw())

```

### Body size by relative tarsus length

```{r}

(p4 <- ggplot(icteridae_data_pruned, aes(x = length, y = rel_tarsus)) + 
  geom_point(aes(group = Genus_species, colour = clade), alpha = 0.6, size = 3) + 
  scale_color_manual(values = c("red", "mediumblue", "gold")) + 
  labs(y = "W/D", caption = "Data from Harmon et al (2010) \nEarly bursts of body size and shape evolution \nare rare in comparative data. Evolution 64: 2385–2396.") + 
  ggtitle("Tarsus/body ratio versus body length\nin 50 blackbird species") + 
  theme(legend.position="bottom", legend.box = "vertical") + 
  theme_bw())

```