Skip to content

Instantly share code, notes, and snippets.

View wilkox's full-sized avatar

David Wilkins wilkox

  • Adelaide, Australia
  • 01:55 (UTC +10:30)
View GitHub Profile
@wilkox
wilkox / pandoc_tinytex.R
Created September 19, 2023 00:05
Install LaTeX packages for pandoc with tinytex
tinytex::tlmgr_install(c("amsfonts", "amsmath", "lm", "unicode-math", "iftex", "listings", "fancyvrb", "longtable", "booktabs", "graphicx", "hyperref", "xcolor", "soul", "geometry", "setspace", "babel", "fontspec", "upquote", "microtype", "csquotes", "natbib", "biblatex", "bibtex", "parskip", "xurl", "bookmark", "footnotehyper", "footnote"))
# Create a grid arrangement of ggplot2 plots with a shared legend
# Original code by Shaun Jackman (http://rpubs.com/sjackman/grid_arrange_shared_legend)
# Source: https://github.com/tidyverse/ggplot2/wiki/Share-a-legend-between-two-ggplot2-graphs
library(ggplot2)
library(gridExtra)
library(grid)
grid_arrange_shared_legend <- function(..., ncol = length(list(...)), nrow = 1, position = c("bottom", "right")) {
# Libraries
library(readr)
library(devtools)
library(SpiecEasi)
library(phyloseq)
library(tibble)
library(igraph)
library(dplyr)
library(stringr)
library(tidyr)
# Libraries
library(readr)
library(SpiecEasi)
library(phyloseq)
library(tibble)
library(igraph)
library(dplyr)
library(stringr)
library(tidyr)
library(ggplot2)
# Vectorised version of the private function getAncestor in ggtree
require(ggtree)
get_ancestors <- function(tree, nodes) {
return(
unique(
unlist(lapply(nodes, function(node) ggtree:::getAncestor(tree, node)))
)
)
}
# Vectorised version of ggtree::expand
require(ggtree)
expand_vectorised <- function(tree_view = NULL, nodes) {
if (length(nodes) == 1) {
return(ggtree::expand(tree_view, nodes))
} else {
return(ggtree::expand(
expand_vectorised(tree_view, nodes[-1]),
nodes[1]
))
# Vectorised version of ggtree::collapse
require(ggtree)
collapse_vectorised <- function(tree_view = NULL, nodes) {
if (length(nodes) == 1) {
return(ggtree::collapse(tree_view, nodes))
} else {
return(ggtree::collapse(
collapse_vectorised(tree_view, nodes[-1]),
nodes[1]
))
multiplot_file <- function(plots = NULL, file, cols = 1, layout = NULL, width = 100, height = 100) {
require(grid)
mm <- function(mm) {return(0.0393701 * mm)}
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(
seq(1, cols * ceiling(numPlots/cols)),
# Libraries
library(readr)
library(SpiecEasi)
library(phyloseq)
library(tibble)
library(igraph)
library(dplyr)
library(stringr)
library(tidyr)
library(ggplot2)
# Libraries
library(readr)
library(SpiecEasi)
library(phyloseq)
library(tibble)
library(igraph)
library(dplyr)
library(stringr)
library(tidyr)
library(ggplot2)