Skip to content

Instantly share code, notes, and snippets.

View emilelatour's full-sized avatar

Emile Latour emilelatour

  • Oregon Health & Science University
  • Portland , OR
View GitHub Profile
@jenniferthompson
jenniferthompson / genericized_dd.Rmd
Last active November 11, 2023 23:56
Example structure for data dictionary + code used for derivation using RMarkdown. Creates three data tables and documents general + field-specific info.
---
title: "Example Data Dictionary"
author: "Jennifer Thompson"
date: "11/1/2018"
output:
html_document:
theme: yeti
code_folding: hide
---
@dpseidel
dpseidel / default_aes.md
Last active February 12, 2021 17:08
Default ggplot2 aesthetics table

Default ggplot2 aesthetics by geom.

geom alpha angle colour family fill fontface height hjust lineheight linetype shape size stroke vjust weight width xmax xmin ymax ymin
GeomAbline NA black 1 0.5
GeomAnnotationMap NA NA grey20 1 0.5
GeomArea NA NA grey20 1 0.5
GeomBar NA NA grey35 1 0.
@benmarwick
benmarwick / rotate-axis-labels-ggplot2.R
Last active March 30, 2024 08:00
I can never remember how to rotate the x-axis labels with ggplot2: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
# Adapted from https://stackoverflow.com/a/7267364/1036500 by Andrie de Vries
# This is it: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
library(ggplot2)
td <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
library(rlang)
# Functions with names ending in `_impl` take quoted expressions as input.
# This removes the need for constant quoting and unquoting
simplify_sum_impl <- function(e1, e2) {
if (is_syntactic_literal(e1) & is_syntactic_literal(e2)) {
return(eval_bare(e1 + e2))
}
if (e1 == 0) {
@tjmahr
tjmahr / ggpreview.R
Created October 2, 2017 12:32
ggpreview - preview ggsave output in system image viewer
library(ggplot2)
# preview a file that would be created by ggsave()
ggpreview <- function(...) {
fname <- tempfile(fileext = ".png")
ggsave(filename = fname, ...)
system2("open", fname)
invisible(NULL)
}
@PurpleBooth
PurpleBooth / README-Template.md
Last active May 3, 2024 18:53
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@jefferys
jefferys / roxygen2MultiFunctionDocumentation.gist.R
Created June 21, 2015 17:29
R function documentation with roxygen2 - multiple functions
#===================================================
# Demo multi-function roxygen2 - three ways to do it
#===================================================
# This shows how things do work, including wierd corner cases, not
# how they should be done. Most of the information comes from
# http://r-pkgs.had.co.nz/man.html
#====================================================
# Demo multi-function roxygen2 page using @describeIn
@nutterb
nutterb / missingSummary.R
Last active March 7, 2023 21:47
Generate a Report of Fields with Missing Values in a REDCap Database Using the redcapAPI package
#### Intended for use with the `redcapAPI` package
#' @name missingSummary
#' @aliases missingSummary.redcapApiConnection
#' @aliases missingSummary.redcapDbConneciton
#' @aliases missingSummary_offline
#' @export missingSummary
#' @export missingSummary.redcapApiConnection
#' @export missingSummary.redcapDbConnection
#' @export missingSummary_offline
#'
@benmarwick
benmarwick / common-sci-symbols.md
Last active December 20, 2022 18:39
Commonly used scientific symbols in pandoc markdown

Commonly used scientific symbols in pandoc markdown

encoding is UTF-8, needs xelatex, like this:

---
output:
  pdf_document:
    latex_engine: xelatex
---
@tomhopper
tomhopper / plot_aligned_series.R
Last active June 25, 2023 17:36
Align multiple ggplot2 graphs with a common x axis and different y axes, each with different y-axis labels.
#' When plotting multiple data series that share a common x axis but different y axes,
#' we can just plot each graph separately. This suffers from the drawback that the shared axis will typically
#' not align across graphs due to different plot margins.
#' One easy solution is to reshape2::melt() the data and use ggplot2's facet_grid() mapping. However, there is
#' no way to label individual y axes.
#' facet_grid() and facet_wrap() were designed to plot small multiples, where both x- and y-axis ranges are
#' shared acros all plots in the facetting. While the facet_ calls allow us to use different scales with
#' the \code{scales = "free"} argument, they should not be used this way.
#' A more robust approach is to the grid package grid.draw(), rbind() and ggplotGrob() to create a grid of
#' individual plots where the plot axes are properly aligned within the grid.