Skip to content

Instantly share code, notes, and snippets.

@mikelove
Created September 14, 2015 01:01
Show Gist options
  • Save mikelove/76a149cb03dd09379245 to your computer and use it in GitHub Desktop.
Save mikelove/76a149cb03dd09379245 to your computer and use it in GitHub Desktop.
interactions ggplot
npg <- 20
mu <- c(200,400,400,800,800,1600)
cond <- rep(rep(c("A","B"),each=npg),3)
geno <- rep(c("X","Y","Z"),each=2*npg)
table(cond, geno)
counts <- rnbinom(6*npg, mu=rep(mu,each=npg), size=1/.01)
d <- data.frame(counts, cond, geno)
library(ggplot2)
plotit <- function(d) {
ggplot(d, aes(x=cond, y=counts, group=geno)) +
geom_jitter(position = position_jitter(width=.1)) +
facet_wrap(~ geno) +
scale_y_log10() +
stat_summary(fun.y=mean, geom="line", colour="red", size=1)
}
plotit(d)
lm(log2(counts) ~ cond + geno + geno:cond)
mu[6] <- 400
counts <- rnbinom(6*npg, mu=rep(mu,each=npg), size=1/.01)
d <- data.frame(counts, cond, geno)
plotit(d)
lm(log2(counts) ~ cond + geno + geno:cond)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment