This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(igraph) | |
library(ggraph) | |
library(gganimate) | |
library(ggforce) | |
#File at https://dl.dropbox.com/s/hxmsut19lelgw33/epinetwork.rds | |
episim <- readRDS("epinetwork.rds") # Saved is the simulation data and an adjacency matrix for the network | |
# Create an undirected graph from this matrix | |
ign <- graph_from_adjacency_matrix(episim$network > 0, "undirected") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires Megrim font: https://fonts.google.com/specimen/Megrim | |
if(FALSE) { | |
install.packages("extrafont") | |
extrafont::loadfonts() | |
} | |
library(ggplot2) | |
ggplot() + | |
scale_x_continuous(expand = c(0,0)) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
`?` <- function(x, y) { | |
y <- substitute(y) | |
if (!is.call(y) || !identical(as.symbol(":"), y[[1]])) stop("Invalid", call. = FALSE) | |
eval(call("if", x, y[[2]], y[[3]])) | |
} | |
T ? 1 | |
#> Error: Invalid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(grid) | |
d <- data.frame(x=rnorm(50), y=rnorm(50), f1 = rep(gl(5,5), 2), f2 = gl(2, 25)) | |
p <- ggplot(d, aes(x,y, group=interaction(f1,f2))) + | |
geom_line(aes(colour=f1, linetype=f2)) + | |
geom_point(aes(colour=f1, shape=f1)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
(df <- tibble( | |
x = c(1, NA, 3, NA), | |
y = c(1, NA, NA, 4), | |
z = 1:4 | |
)) | |
#> # A tibble: 4 × 3 | |
#> x y z | |
#> <dbl> <dbl> <int> | |
#> 1 1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(dplyr) | |
library(grid) | |
library(gridExtra) | |
add_centered_title <- function(p, text, font_size){ | |
title.grob <- textGrob( | |
label = text, | |
gp = gpar(fontsize = font_size, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(future) | |
trim_model <- function(model, predictor = predict, ..., ignore_warnings = TRUE) { | |
# Cache the correct output | |
true_pred <- predictor(model, ...) | |
# Treat prediction warnings as errors? | |
if (!ignore_warnings) { | |
old_ops <- options(warn = 2) | |
on.exit(options(old_ops)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun_labels <- function(x) sprintf("<b>%s</b>", x) | |
ggplot() + | |
scale_x(breaks = c('a','b','c')) + | |
theme(axis.label = element_sticker(grob = fancyGrob, dictionary = fun_labels)) | |
my_labels <- tibble(label = letters[1:3], grobs = I(lapply(1:3, fancyGrob))) |