Skip to content

Instantly share code, notes, and snippets.

View dpastoor's full-sized avatar

Devin Pastoor dpastoor

  • A2-Ai
  • Rockville, MD
View GitHub Profile
# 200 mg dose ID's overlaid
ggplot(data = CleanedPK200, aes(x = TAD, y = CONC4873)) +
geom_point(aes(group = ID, color = ID), size = 3) +
geom_line(aes(group = ID, color = ID), size = 1) +
labs(title = "200 mg cohort WCK 4873 CONC-TIME") +
ylab("Concentration (ng/mL)") + xlab("Time After Dose (hrs)") +
theme(axis.title.x = element_text(size=17)) +
theme(axis.title.y = element_text(size=17)) +
theme(title = element_text(size=20)) +
scale_y_log10()
This post examines the features of [R Markdown](http://www.rstudio.org/docs/authoring/using_markdown)
using [knitr](http://yihui.name/knitr/) in Rstudio 0.96.
This combination of tools provides an exciting improvement in usability for
[reproducible analysis](http://stats.stackexchange.com/a/15006/183).
Specifically, this post
(1) discusses getting started with R Markdown and `knitr` in Rstudio 0.96;
(2) provides a basic example of producing console output and plots using R Markdown;
(3) highlights several code chunk options such as caching and controlling how input and output is displayed;
(4) demonstrates use of standard Markdown notation as well as the extended features of formulas and tables; and
(5) discusses the implications of R Markdown.
@dpastoor
dpastoor / forestplotexample
Created August 14, 2013 15:02
Example forest plot using ggplot2
library(ggplot2)
dat <- data.frame(group = factor(c("Infliximab","Etanercept","Adalimumab","Golimumab","Certolizumab","Abatacept","Rituximab","Tocilizumab","Total"),
levels=c("Total","Certolizumab","Golimumab","Adalimumab","Etanercept","Infliximab","Tocilizumab","Rituximab","Abatacept")),
cen = c(1.88,2.67,2.35,2.14,5.08,1.68,2.11,2.01,2.16),
low = c(1.01,1.44,1.52,1.59,3.46,1.47,1.64,1.57,1.83),
high = c(3.51,4.94,3.65,2.89,7.48,1.90,2.72,2.57,2.55))
theme_ind <- function(...) {
theme(legend.text = element_text(size = 18),
legend.title = element_text(size = 20),
axis.title.x = element_text(size = 22, face = "bold"),
axis.title.y = element_text(size = 22, face = "bold"),
axis.text.x = element_text(color = "black", size = 18),
axis.text.y = element_text(color = "black", size = 18),
strip.text.x = element_text(color = "black", size = 16, face = "bold"))
}

Notes:

  • I've tried to break up in to separate pieces, but it's not always possible: e.g. knowledge of data structures and subsetting are tidy intertwined.

  • Level of Bloom's taxonomy listed in square brackets, e.g. http://bit.ly/15gqPEx. Few categories currently assess components higher in the taxonomy.

Programming R curriculum

Data structures

@dpastoor
dpastoor / 0_reuse_code.js
Created November 7, 2013 02:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dpastoor
dpastoor / setup.R
Last active December 28, 2015 04:48
Setup file for a fresh R install or new computer
libraries <- c(
"bear",
"deSolve",
"devtools",
"dplyr",
"formatR",
"ggplot2",
"gridExtra",
"installr",
"knitr",
#'Saves a ggplot graphic to a file and creates the code to include it in a
#'LaTeX document.
#'
#'Saves a ggplot graphic to a file and creates the code to include it in a
#'LaTeX document. The code is inspired by xtable() from the xtable-package.
#'
#'
#'@param ... arguments passed to the (\code{\link{ggsave}}) function
#'@param caption The caption. Default to NULL, indicating no caption.
#'@param label The label. Default to NULL, indicating no label.
@dpastoor
dpastoor / server.R
Created January 11, 2014 01:16 — forked from jknowles/server.R
library(shiny)
shinyServer(function(input,output){
output$distPlot<-reactivePlot(function(){
dist<-rnorm(input$obs)
p<-qplot(dist,binwidth=0.1)+geom_vline(xintercept=mean(dist))+theme_dpi()
p<-p+coord_cartesian(xlim=c(-4,4))+geom_vline(xintercept=median(dist),color=I("red"))
print(p)
})
@dpastoor
dpastoor / css_rendering
Last active August 29, 2015 13:55
custom css in RMD
# add to .Rmd file and place the a custom.css file with the desired css in the same directory
options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
require(markdown)
markdownToHTML(inputFile, outputFile, stylesheet='custom.css')
}
)