---
title: "South America (based on Glottolog)"
output: flexdashboard::flex_dashboard
---

Column {data-width=600}
-------------------------------------

### Map

```{r, echo=FALSE}
library(lingtypology)
s.america <- glottolog.modified[glottolog.modified$macro_area == "South America",]
s.america$family <- sapply(s.america$affiliation, function(x){
  unlist(strsplit(x, ", "))[1]})
s.america <- s.america[s.america$family != "Spurious",]
s.america <- s.america[!is.na(s.america$languoid),]
s.america[is.na(s.america$family),8] <- "Unclassifiable"
set.seed(42)
mycol <- substr(sample(rainbow(length(s.america$family)), length(s.america$family)), 1, 7)
map.feature(languages = s.america$languoid,
            features = s.america$family,
            legend = F,
            color = mycol)
```

Column {data-width=400}
-------------------------------------
  
### Legend
  
```{r, echo = F}
legend <- data.frame(family = unique(s.america$family))
library(DT)
datatable(legend, rownames = FALSE) %>% 
  formatStyle(
    'family',
    backgroundColor = styleEqual(legend$family, mycol))
```