Skip to content

Instantly share code, notes, and snippets.

@ohofmann
Created June 11, 2012 16:50
Show Gist options
  • Select an option

  • Save ohofmann/2911193 to your computer and use it in GitHub Desktop.

Select an option

Save ohofmann/2911193 to your computer and use it in GitHub Desktop.

KNITR SETUP

opts_chunk$set(tidy=TRUE, cache=FALSE, highlight=TRUE, figalign="center", warning=FALSE,  error=FALSE, message=FALSE, fig.height=11, fig.width=11)

EXAMPLE CHUNK

library(ggplot2)
library(xtable)

EXAMPLE ggplot generation and printing

colors <- factor(df$foo)
p <- ggplot(data=df, aes(x=xval, y=-log10(yval), label=symbol, color=colors)) + geom_point(size=8, alpha=0.7) + scale_colour_discrete(name = "legend title") + xlab("xlab") + ylab("ylab") 

print out plot

print(p)

EXAMPLE table generation and printing

Table1 - Table title

table1 <- xtable(df, label=NULL, digits=c(1,1,1,6,0,1)) ## here you have 6 columns and "digits = the number of digits to round to for each column 
print(table1, type="html",include.rownames=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment