Last updated: 2024-06-20

Checks: 6 1

Knit directory: LocksofLineage/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20231117) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
~/Desktop/GitHub/LocksofLineage/data/data_pruned_ordered.csv data/data_pruned_ordered.csv

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version c036a0b. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store
    Ignored:    data/RevBayes_Data/.DS_Store

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/AABA_analysis.Rmd) and HTML (docs/AABA_analysis.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 24ecbbf Sarah E Taylor 2024-06-17 Added code to save the formatted dataframes.
html 768856f Sarah E Taylor 2024-03-17 Build site.
Rmd 3818f0b Sarah E Taylor 2024-03-17 Analysis for the poster.

Set up

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(janitor)

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(ape)

Attaching package: 'ape'

The following object is masked from 'package:dplyr':

    where
library(phytools)
Loading required package: maps

Attaching package: 'maps'

The following object is masked from 'package:purrr':

    map
#Library for upset plot
library(ComplexUpset)
library(eulerr)
#Map the families onto the superfamilies
superfamily_mapping <- data.frame(
  family = c("Lorisidae", "Galagonidae", "Daubentoniidae","Indridae", "Lemuridae", "Cheirogaleidae", "Megaladapidae", "Tarsiidae", "Cebidae", "Callitrichidae", "Hylobatidae",     "Pongidae", "Hominidae", "Cercopithecidae"),
  superfamily = c("Lorisiformes", "Lorisiformes", "Lemuriformes", "Lemuriformes", "Lemuriformes", "Lemuriformes", "Lemuriformes","Tarsiiformes", "Platyrrhini", "Platyrrhini", "Hominoidea", "Hominoidea", "Hominoidea", "Cercopithecoidea"))


df_trait_values <- read_csv("data/Raw_Data/data_to_use.csv") %>%
  clean_names() %>%  
  mutate(
    natal_coat = if_else(natal_coat == "Yes", 1, 0),
    sexual_dichromatism = if_else(sexual_dichromatism == "Yes", 1, 0)
  ) %>%
  mutate(
    natal_coat_type_simple = case_when(
      natal_coat_type %in% c("Con to dad", "con to both", "con to mom") ~ "conspicuous",
      natal_coat_type == "incon" ~ "inconspicuous",
      TRUE ~ "none"  # This catches all other cases
    )
  ) %>%
  mutate(
    natal_coat_conspicuous = ifelse(natal_coat_type_simple == "conspicuous", 1, 0),
    natal_coat_inconspicuous = ifelse(natal_coat_type_simple == "inconspicuous", 1, 0),
    natal_coat_present = ifelse(natal_coat_type_simple %in% c("conspicuous", "inconspicuous"), 1, 0)
  ) %>%
  mutate(
    maturation_color_change = case_when(
      natal_coat_type == "Con to dad" ~ "Males only",
      natal_coat_type == "con to mom" ~ "Females only",
      natal_coat_type == "con to both" ~ "Both",
      TRUE ~ "None"
    ),
    maturation_males_only = as.integer(maturation_color_change == "Males only"),
    maturation_females_only = as.integer(maturation_color_change == "Females only"),
    maturation_both = as.integer(maturation_color_change == "Both"),
    maturation_none = as.integer(maturation_color_change == "None")
  ) %>%
  mutate(sexual_dichromatism_complete = ifelse(sexual_dichromatism_type == "Complete", 1, 0),
         sexual_dichromatism_partial = ifelse(sexual_dichromatism_type == "Partial", 1, 0),
         sexual_dichromatism_present = ifelse(sexual_dichromatism_type %in% c("Complete", "Partial"), 1, 0)
  ) %>%
  mutate(
  all_color_traits = ifelse(natal_coat | sexual_dichromatism | 
                            maturation_both | maturation_females_only | maturation_males_only, 1, 0)
)%>%
  select(
    family, genus, species,
    natal_coat, natal_coat_type, natal_coat_type_simple, natal_coat_conspicuous,       natal_coat_inconspicuous, natal_coat_present,
    sexual_dichromatism, sexual_dichromatism_type, sexual_dichromatism_complete, sexual_dichromatism_partial, sexual_dichromatism_present,
    size_dimorphism, maturation_color_change,
    maturation_males_only, maturation_females_only, 
    maturation_both, maturation_none,
    all_color_traits
  )
Rows: 238 Columns: 17
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (16): family, Genus, species, subspecies, Sexual_dimorphism, Sexual_Dimo...
dbl  (1): Size_Dimorphism

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#read in mammal tree
mammaltree <- read.tree("data/Raw_Data/MamPhy_BDvr_Completed_v2_tree0000.tre")
summary(mammaltree)

Phylogenetic tree: mammaltree 

  Number of tips: 5987 
  Number of nodes: 5986 
  Branch lengths:
    mean: 2.680715 
    variance: 24.17565 
    distribution summary:
       Min.     1st Qu.      Median     3rd Qu.        Max. 
  0.0000000   0.5284341   1.3073255   2.9454665 106.6007500 
  No root edge.
  First ten tip labels: X_Shuotherium 
                        X_Pseudotribos
                        X_Asfaltomylos
                        X_Obdurodon
                        Zaglossus_bartoni
                        Zaglossus_bruijnii
                        Zaglossus_attenboroughi
                        Tachyglossus_aculeatus
                        Ornithorhynchus_anatinus
                        X_Teinolophos
  No node labels.
# Assuming mammaltree has already been loaded with read.tree() as in the provided code
Binary_traits_combined <- df_trait_values %>%
  unite("species", genus, species, sep = "_") %>%
  mutate(species = str_to_title(species)) %>%
  mutate(family = str_to_title(family)) %>%
  filter(species %in% mammaltree$tip.label) 

# Format tree to match data
pruned.tree <- drop.tip(mammaltree, setdiff(mammaltree$tip.label, Binary_traits_combined$species))

data_pruned_ordered <- Binary_traits_combined %>%
  arrange(match(species, pruned.tree$tip.label)) %>%
  left_join(superfamily_mapping, by = "family") %>%
  column_to_rownames("species")
# Optionally save the data frame to a csv
write.csv(data_pruned_ordered, file = "~/Desktop/GitHub/LocksofLineage/data/data_pruned_ordered.csv", row.names = TRUE)

# Optionally save the tree into a .nex file
write.nexus(pruned.tree, file = "pruned_tree.nex")

Run the phytools fitPagel model

natal_coats <- setNames(data_pruned_ordered$natal_coat,rownames(data_pruned_ordered))
sexual_dichromatism <- setNames(data_pruned_ordered$sexual_dichromatism,rownames(data_pruned_ordered)) 
size_dimorphism <- setNames(data_pruned_ordered$size_dimorphism,rownames(data_pruned_ordered))
all_color_traits <- setNames(data_pruned_ordered$all_color_traits,rownames(data_pruned_ordered))
# Correlations between natal coats and sexual dichromatism
natal_coats_and_sexual_dichrom_pagel <- fitPagel(pruned.tree, natal_coats, sexual_dichromatism)

anova(natal_coats_and_sexual_dichrom_pagel)
                                        log(L) d.f.      AIC       weight
independent                          -284.6806    4 577.3613 2.328933e-08
natal_coats_and_sexual_dichrom_pagel -263.1054    8 542.2107 1.000000e+00
# Correlations between size dimorphism and the color traits (natal coats and sexual dichromatism)
# size_and_color_pagel <- fitPagel(pruned.tree, size_dimorphism, all_color_traits)
# Plot the natal coat and sexual dichromatism model
plot(natal_coats_and_sexual_dichrom_pagel, lwd.by.rate=TRUE)

Version Author Date
768856f Sarah E Taylor 2024-03-17
#plot(size_and_color_pagel, lwd.by.rate=TRUE)

Other plots for the poster

#scale_fill_manual(values=c("Lorisidae" = "darkseagreen", "Galagonidae"= "mediumseagreen", "Daubentoniidae" = "chocolate4", "Indridae" = "chocolate2", "Lemuridae" = "salmon", "Cheirogaleidae" = "coral3", "Megaladapidae" = "sienna3", "Tarsiidae" = "gold", "Cebidae" = "cyan", "Callitrichidae" = "turquoise",   "Cercopithecidae" = "burlywood2", "Hylobatidae" = "maroon", "Pongidae" = "violetred2", "Hominidae" = "deeppink1"),)

# Color palatte for streps
tailwind_colors <- c(
  "Blue" = "#000cee",
  "Zaffre" = "#2107a7",
  "ElectricIndigo" = "#6200ff",
  "Indigo" = "#5c0096",
  "DarkViolet" = "#9c00b8",
  "HotMagenta" = "#ea2cda",
  "Fandango" = "#b8008a",
   "Cyan (RGB)" = "#00fffb",
  "Spring Green" = "#00f56a",
  "Forest Green" = "#009138",
  "Gold" = "#ffd500",
  "Pumpkin" = "#ff6a00",
  "Turkey Red" = "#ac0000"
)



# Define the traits
set_attributes <- c(
  'natal_coat_present',
  'natal_coat_conspicuous', 
  'size_dimorphism',
  'sexual_dichromatism_complete', 
  'sexual_dichromatism_partial',
  'maturation_males_only',
  'maturation_females_only',
  'maturation_both')

# Create the plot
upset(
    data_pruned_ordered,
    set_attributes,  
    base_annotations = list(
        'Intersection size' = intersection_size(
            counts = TRUE,
            mapping = aes(fill = family)  # Ensure 'family' is the correct column
        ) + scale_fill_manual(values = c(
            "Lorisidae" = "#ea2cda", 
            "Galagonidae" = "#b8008a", 
            "Daubentoniidae" = "#9c00b8", 
            "Indridae" = "#5c0096", 
            "Lemuridae" = "#000CEE", 
            "Cheirogaleidae" = "#6200ff", 
            "Megaladapidae" = "#2107a7", 
            "Tarsiidae" = "#00fffb",  
            "Cebidae" = "#00f56a", 
            "Callitrichidae" = "#009138", 
            "Cercopithecidae" = "#ffd500", 
            "Hylobatidae" = "#ff6a00", 
            "Pongidae" = "#ac0000", 
            "Hominidae" = "#ac0000"
        ))
    ),
    width_ratio = 0.1
)
Warning in upset_data(data, intersect, mode = mode, encode_sets = encode_sets,
: Converting non-logical columns to binary: natal_coat_present,
natal_coat_conspicuous, size_dimorphism, sexual_dichromatism_complete,
sexual_dichromatism_partial, maturation_males_only, maturation_females_only,
maturation_both
Warning in upset_data(data, intersect, mode = mode, encode_sets = encode_sets,
: Detected missing values in the columns indicating sets, coercing to FALSE
Warning in plot_theme(plot): The `legend.text.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.title.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.text.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.title.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.text.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.title.align` theme element is not
defined in the element hierarchy.

Version Author Date
768856f Sarah E Taylor 2024-03-17
upset(
    data_pruned_ordered, set_attributes, width_ratio=0.1,
    annotations =list(
        'Family Percentages'=list(
            aes=aes(x=intersection, fill=family),
            geom=list(
                geom_bar(stat='count', position='fill', na.rm=TRUE),
                geom_text(
                    aes(
                        label=!!aes_percentage(relative_to='group'),
                        group=family,
                        color=ifelse(family == 'Cercopithecidae', 'show', 'hide')
                    ),
                    stat='count',
                    position=position_fill(vjust = .5)
                ),
                scale_y_continuous(labels=scales::percent_format())
            )
        )
    )
)
Warning in upset_data(data, intersect, mode = mode, encode_sets = encode_sets,
: Converting non-logical columns to binary: natal_coat_present,
natal_coat_conspicuous, size_dimorphism, sexual_dichromatism_complete,
sexual_dichromatism_partial, maturation_males_only, maturation_females_only,
maturation_both
Warning in upset_data(data, intersect, mode = mode, encode_sets = encode_sets,
: Detected missing values in the columns indicating sets, coercing to FALSE
Warning: The dot-dot notation (`..prop..`) was deprecated in ggplot2 3.4.0.
ℹ Please use `after_stat(prop)` instead.
ℹ The deprecated feature was likely used in the ComplexUpset package.
  Please report the issue at
  <https://github.com/krassowski/complex-upset/issues>.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
generated.
Warning in plot_theme(plot): The `legend.text.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.title.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.text.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.title.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.text.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.title.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.text.align` theme element is not
defined in the element hierarchy.
Warning in plot_theme(plot): The `legend.title.align` theme element is not
defined in the element hierarchy.

Version Author Date
768856f Sarah E Taylor 2024-03-17
VennDiag <- euler(c("A" = 62 + 67, "B" = 13 + 67, "A&B" = 67))
plot(VennDiag, quantities = TRUE, font = 1, cex = 1, alpha = 0.5, fill=c("#F38C79","#D8EDDB"), labels = c("Natal Coats", "Sexual Dichromatism"))

Version Author Date
768856f Sarah E Taylor 2024-03-17

sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Denver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] eulerr_7.0.2       ComplexUpset_1.3.3 phytools_2.1-1     maps_3.4.2        
 [5] ape_5.8            janitor_2.2.0      lubridate_1.9.3    forcats_1.0.0     
 [9] stringr_1.5.1      dplyr_1.1.4        purrr_1.0.2        readr_2.1.5       
[13] tidyr_1.3.1        tibble_3.2.1       ggplot2_3.5.1      tidyverse_2.0.0   
[17] workflowr_1.7.1   

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1        farver_2.1.2            optimParallel_1.0-2    
 [4] fastmap_1.2.0           combinat_0.0-8          promises_1.3.0         
 [7] digest_0.6.35           timechange_0.3.0        lifecycle_1.0.4        
[10] processx_3.8.4          polylabelr_0.2.0        magrittr_2.0.3         
[13] compiler_4.3.3          rlang_1.1.3             sass_0.4.9             
[16] tools_4.3.3             igraph_2.0.3            utf8_1.2.4             
[19] yaml_2.3.8              knitr_1.45              phangorn_2.11.1        
[22] clusterGeneration_1.3.8 labeling_0.4.3          bit_4.0.5              
[25] mnormt_2.1.1            scatterplot3d_0.3-44    expm_0.999-9           
[28] withr_3.0.0             numDeriv_2016.8-1.1     polyclip_1.10-6        
[31] grid_4.3.3              fansi_1.0.6             git2r_0.33.0           
[34] colorspace_2.1-0        scales_1.3.0            iterators_1.0.14       
[37] MASS_7.3-60.0.1         cli_3.6.2               crayon_1.5.2           
[40] rmarkdown_2.27          generics_0.1.3          rstudioapi_0.16.0      
[43] httr_1.4.7              tzdb_0.4.0              cachem_1.1.0           
[46] parallel_4.3.3          vctrs_0.6.5             Matrix_1.6-5           
[49] jsonlite_1.8.8          callr_3.7.6             patchwork_1.2.0        
[52] hms_1.1.3               bit64_4.0.5             foreach_1.5.2          
[55] jquerylib_0.1.4         glue_1.7.0              codetools_0.2-19       
[58] ps_1.7.6                stringi_1.8.4           gtable_0.3.5           
[61] later_1.3.2             quadprog_1.5-8          munsell_0.5.1          
[64] pillar_1.9.0            htmltools_0.5.8.1       R6_2.5.1               
[67] doParallel_1.0.17       rprojroot_2.0.4         vroom_1.6.5            
[70] evaluate_0.23           lattice_0.22-5          highr_0.10             
[73] snakecase_0.11.1        httpuv_1.6.15           bslib_0.7.0            
[76] Rcpp_1.0.12             fastmatch_1.1-4         coda_0.19-4.1          
[79] nlme_3.1-164            whisker_0.4.1           xfun_0.44              
[82] fs_1.6.4                getPass_0.2-4           pkgconfig_2.0.3