Last updated: 2022-02-21

Checks: 7 0

Knit directory: Amphibolis_Posidonia_Comparison/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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(20210414) 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.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

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 d06c086. 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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/OTT.nb.html
    Ignored:    analysis/plotGenes.nb.html
    Ignored:    analysis/plotRgenes.nb.html

Untracked files:
    Untracked:  data/~$R_genes.xlsx

Unstaged changes:
    Modified:   analysis/Orthofinder.Rmd
    Modified:   data/arabidopsis_gene_level_comparison.xlsx
    Modified:   data/arabidopsis_gene_level_comparison_only_losts.xlsx
    Modified:   data/arabidopsis_gene_level_counts.xlsx

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/plotRgenes.Rmd) and HTML (docs/plotRgenes.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 d06c086 Philipp Bayer 2022-02-21 summaryTable
html 48be9b2 Philipp Bayer 2022-02-21 Build site.
Rmd d3cdc00 Philipp Bayer 2022-02-21 better plot
html 292db59 Philipp Bayer 2021-10-18 Build site.
Rmd 95586f9 Philipp Bayer 2021-10-07 Add missing data
html 95586f9 Philipp Bayer 2021-10-07 Add missing data
html c0db4a5 Philipp Bayer 2021-10-07 Build site.
Rmd 08b28ea Philipp Bayer 2021-10-07 wflow_publish(files = c("analysis/*"))

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.1.1
-- Attaching packages --------------------------------------- tidyverse 1.3.1 --
v ggplot2 3.3.5     v purrr   0.3.4
v tibble  3.1.5     v dplyr   1.0.7
v tidyr   1.1.4     v stringr 1.4.0
v readr   2.0.2     v forcats 0.5.1
Warning: package 'ggplot2' was built under R version 4.1.1
Warning: package 'tibble' was built under R version 4.1.1
Warning: package 'tidyr' was built under R version 4.1.1
Warning: package 'readr' was built under R version 4.1.1
Warning: package 'purrr' was built under R version 4.1.1
Warning: package 'dplyr' was built under R version 4.1.1
Warning: package 'stringr' was built under R version 4.1.1
Warning: package 'forcats' was built under R version 4.1.1
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
library(wesanderson)
Warning: package 'wesanderson' was built under R version 4.1.1
library(ggtree)
ggtree v3.0.4  For help: https://yulab-smu.top/treedata-book/

If you use ggtree in published research, please cite the most appropriate paper(s):

1. Guangchuang Yu. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics, 2020, 69:e96. doi:10.1002/cpbi.96
2. Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution 2018, 35(12):3041-3043. doi:10.1093/molbev/msy194
3. Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution 2017, 8(1):28-36. doi:10.1111/2041-210X.12628

Attaching package: 'ggtree'
The following object is masked from 'package:tidyr':

    expand
library(ggtreeExtra)
Warning: package 'ggtreeExtra' was built under R version 4.1.1
ggtreeExtra v1.2.3  For help: https://yulab-smu.top/treedata-book/

If you use ggtreeExtra in published research, please cite the paper:

S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ggtreeExtra: Compact visualization of richly annotated phylogenetic data. Molecular Biology and Evolution 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166
library(kableExtra)
Warning: package 'kableExtra' was built under R version 4.1.2

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

    group_rows
knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())

Visualising R-gene differences here

pal <- wes_palette("Zissou1", 3, type = "continuous")

df <- readxl::read_xlsx('./data/R_genes.xlsx')
df %>% ggplot(aes(fill=Class, x=Genome, y=Count)) + geom_bar(stat='identity') +
    scale_fill_manual(values=pal) +  
 coord_flip() +  cowplot::theme_minimal_vgrid() +
    theme(axis.text.y = element_text(face = "italic")) 

pal <- wes_palette("Zissou1", 4, type = "continuous")

df2 <- df %>% mutate(Class2= case_when(str_detect(Subclass, pattern = 'TN') ~ 'NLR (TNL)',
                                str_detect(Subclass, pattern = '^R') ~ Subclass,
                                TRUE ~ 'NLR (CNL)'))
df2 %>% ggplot(aes(fill=Class2, x=Genome, y=Count)) + geom_bar(stat='identity') +
    scale_fill_manual(values=pal)  + coord_flip() +  cowplot::theme_minimal_vgrid() +
    theme(axis.text.y = element_text(face = "italic")) 

df2 %>% dplyr::filter(Genome %in% c('P. australis', 'Z. marina', 'Z. muelleri', 'O. sativa', 'A. antarctica', 'A. thaliana')) %>% 
  ggplot(aes(fill=Class2, x=factor(Genome, levels=c('Z. marina', 'Z. muelleri', 'P. australis', 'A. antarctica', 'O. sativa', 'A. thaliana' )), y=Count)) + 
  geom_bar(stat='identity') +
    scale_fill_manual(values=pal)  + coord_flip() +  cowplot::theme_minimal_vgrid() +
    theme(axis.text.y = element_text(face = "italic")) +
  xlab('Genome') +
  labs(fill='Class')

Let’s link those to the phylogeny we got from timetree.org

tree <- ape::read.tree('./data/timetree_species.nwk')
tree$tip.label <- c('O. lucimarinus', 'C. reinhardtii', 'P. patens', 'S. moellendorffii', 'O. sativa', 'B. distachyon', 'Z. mays', 'P. australis', 'Z. marina', 'Z. muelleri', 'A. antarctica', 'S. polyrhiza', 'L. gibba', 'V. vinifera', 'A. thaliana', 'S. parvula', 'P. trichocarpa', 'A. trichopada')
p2 <- df2 %>% ggplot(aes(fill=Class2, x=Genome, y=Count)) + geom_bar(stat='identity') +
    scale_fill_manual(values=pal)  + coord_flip() +  cowplot::theme_minimal_vgrid() +
    theme(axis.text.y = element_text(face = "italic")) 
p1 <- ggtree(tree)
p1

df2$label <- df2$Genome
# get species not in tree
subtree <- ape::drop.tip(tree, tree$tip.label[!tree$tip.label %in% df2$label])
p1 <- ggtree(subtree)
p1 

df3 <- as.data.frame(df2)
df3$label <- df3$Genome
df3$id <- df3$label
# code from https://thackl.github.io/ggtree-composite-plots

tree_y <-  function(ggtree, data){
  if(!inherits(ggtree, "ggtree"))
    stop("not a ggtree object")
  left_join(select(data, label), select(ggtree$data, label, y)) %>%
    pull(y)
}
# overwrite the default expand for continuous scales
scale_y_tree <- function(expand=expand_scale(0, 0.6), ...){
    scale_y_continuous(expand=expand, ...)
}

# get the range of the ggtree y-axis data
tree_ylim <- function(ggtree){
  if(!inherits(ggtree, "ggtree"))
    stop("not a ggtree object")
  range(ggtree$data$y)
}

# plot data next to a ggtree aligned by shared labels
ggtreeplot <- function(ggtree, data = NULL, mapping = aes(), flip=FALSE,
     expand_limits=expand_scale(0,.6), ...){
  
  if(!inherits(ggtree, "ggtree"))
    stop("not a ggtree object")

  # match the tree limits
  limits <- tree_ylim(ggtree)
  limits[1] <- limits[1] + (limits[1] * expand_limits[1]) - expand_limits[2]
  limits[2] <- limits[2] + (limits[2] * expand_limits[3]) + expand_limits[4]
  
  if(flip){
    mapping <- modifyList(aes_(x=~x), mapping)
    data <- mutate(data, x=tree_y(ggtree, data))
    gg <- ggplot(data=data, mapping = mapping, ...) +
      scale_x_continuous(limits=limits, expand=c(0,0))
  }else{
    mapping <- modifyList(aes_(y=~y), mapping)
    data <- mutate(data, y=tree_y(ggtree, data))
    gg <- ggplot(data=data, mapping = mapping, ...) +
      scale_y_continuous(limits=limits, expand=c(0,0))
  }
  gg
}

# get rid of superfluous axis - this works after coord_flip, so it also works
# for the rotated histogram
no_y_axis <- function () 
  theme(axis.line.y = element_blank(), 
        axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank())
p3 <-  ggtree(subtree) + geom_tiplab(align=TRUE, fontface='italic') +
  scale_x_continuous(expand=expand_scale(0.8)) + scale_y_tree()
Warning: `expand_scale()` is deprecated; use `expansion()` instead.

Warning: `expand_scale()` is deprecated; use `expansion()` instead.
Scale for 'y' is already present. Adding another scale for 'y', which will
replace the existing scale.
myhist <- ggtreeplot(p3, df3, aes(y=Count, color=Class2, fill=Class2), flip=TRUE) +
  geom_col(aes(fill=Class2,group=Class2,color=Class2)) + 
  #theme(legend.position="none") +
  coord_flip() + no_y_axis()  + 
  theme(legend.position=c(0.6, 0.87)) + 
  labs(fill='Class', color='Class')
Warning: `expand_scale()` is deprecated; use `expansion()` instead.
Joining, by = "label"
p3 + myhist 

Quick summary stats

df %>% group_by(Genome, Class) %>% summarise(sum=sum(Count)) %>% kbl() %>%
  kable_styling()
`summarise()` has grouped output by 'Genome'. You can override using the `.groups` argument.
Genome Class sum
A. antarctica NLR 739
A. antarctica RLK 958
A. antarctica RLP 251
A. thaliana NLR 3415
A. thaliana RLK 2532
A. thaliana RLP 752
A. trichopada NLR 1159
A. trichopada RLK 1239
A. trichopada RLP 665
B. distachyon NLR 3058
B. distachyon RLK 2789
B. distachyon RLP 750
C. reinhardtii NLR 2774
C. reinhardtii RLK 6
C. reinhardtii RLP 691
O. lucimarinus NLR 193
O. lucimarinus RLK 5
O. lucimarinus RLP 43
O. sativa NLR 4413
O. sativa RLK 3746
O. sativa RLP 1139
P. australis NLR 588
P. australis RLK 1147
P. australis RLP 285
P. patens NLR 1494
P. patens RLK 1660
P. patens RLP 649
P. trichocarpa NLR 4524
P. trichocarpa RLK 4217
P. trichocarpa RLP 1606
Z. marina NLR 755
Z. marina RLK 1469
Z. marina RLP 308
Z. muelleri NLR 1256
Z. muelleri RLK 1814
Z. muelleri RLP 551

sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

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

other attached packages:
 [1] kableExtra_1.3.4  ggtreeExtra_1.2.3 ggtree_3.0.4      wesanderson_0.3.6
 [5] forcats_0.5.1     stringr_1.4.0     dplyr_1.0.7       purrr_0.3.4      
 [9] readr_2.0.2       tidyr_1.1.4       tibble_3.1.5      ggplot2_3.3.5    
[13] tidyverse_1.3.1   workflowr_1.6.2  

loaded via a namespace (and not attached):
 [1] nlme_3.1-152       fs_1.5.0           lubridate_1.8.0    webshot_0.5.2     
 [5] httr_1.4.2         rprojroot_2.0.2    tools_4.1.0        backports_1.2.1   
 [9] bslib_0.3.1        utf8_1.2.2         R6_2.5.1           DBI_1.1.1         
[13] lazyeval_0.2.2     colorspace_2.0-2   withr_2.4.2        tidyselect_1.1.1  
[17] compiler_4.1.0     git2r_0.28.0       cli_3.0.1          rvest_1.0.2       
[21] xml2_1.3.2         labeling_0.4.2     sass_0.4.0         scales_1.1.1      
[25] systemfonts_1.0.4  digest_0.6.28      yulab.utils_0.0.4  rmarkdown_2.11    
[29] svglite_2.1.0      pkgconfig_2.0.3    htmltools_0.5.2    highr_0.9         
[33] dbplyr_2.1.1       fastmap_1.1.0      rlang_0.4.12       readxl_1.3.1      
[37] rstudioapi_0.13    farver_2.1.0       gridGraphics_0.5-1 jquerylib_0.1.4   
[41] generics_0.1.1     jsonlite_1.7.2     magrittr_2.0.1     ggplotify_0.1.0   
[45] patchwork_1.1.1    Rcpp_1.0.7         munsell_0.5.0      fansi_0.5.0       
[49] ape_5.5            ggnewscale_0.4.5   lifecycle_1.0.1    stringi_1.7.5     
[53] whisker_0.4        yaml_2.2.1         grid_4.1.0         parallel_4.1.0    
[57] promises_1.2.0.1   crayon_1.4.1       lattice_0.20-44    cowplot_1.1.1     
[61] haven_2.4.3        hms_1.1.1          knitr_1.36         pillar_1.6.4      
[65] reprex_2.0.1       glue_1.4.2         evaluate_0.14      ggfun_0.0.5       
[69] modelr_0.1.8       vctrs_0.3.8        treeio_1.16.2      tzdb_0.1.2        
[73] httpuv_1.6.3       cellranger_1.1.0   gtable_0.3.0       assertthat_0.2.1  
[77] xfun_0.27          broom_0.7.9        tidytree_0.3.7     later_1.3.0       
[81] viridisLite_0.4.0  aplot_0.1.2        ellipsis_0.3.2