Skip to content

Instantly share code, notes, and snippets.

@bhive01
Last active January 5, 2016 19:22
Show Gist options
  • Save bhive01/aa15ac57546bc64b2f08 to your computer and use it in GitHub Desktop.
Save bhive01/aa15ac57546bc64b2f08 to your computer and use it in GitHub Desktop.
## short version
require(ggplot2)
graphdata <- structure(list(X12136 = c(79L, 15L, 60L, 33L, 53L, 89L, 21L,
25L, 83L, 3L, 64L, 47L, 39L, 1L, 99L, 69L, 9L, 59L, 8L, 10L,
23L, 74L, 65L, 81L, 42L, 79L, 15L, 60L, 33L, 53L, 89L, 21L, 25L,
83L, 3L, 64L, 47L, 39L, 1L, 99L, 69L, 9L, 59L, 8L, 10L, 23L,
74L, 65L, 81L, 42L, 79L, 15L, 60L, 33L, 53L, 89L, 21L, 25L, 83L,
3L), pheno = structure(list(Condition = structure(c(2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), .Label = c("Diseased", "Normal"
), class = "factor")), .Names = "Condition", row.names = c(NA,
-60L), class = "data.frame")), row.names = c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
"49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
"60"), class = "data.frame", .Names = c("X12136", "pheno"))
ggplot(data=graphdata, aes(x = pheno, y = X12136)) + geom_point()
############# Longer version
require(affy)
require(ggplot2)
require(dplyr)
set.seed(81)
mat <- matrix(data=sample(1:100), nrow=12136, ncol=60)
new.set <- new("ExpressionSet", exprs=mat)
pdat <- data.frame(Condition=rep(c("Normal", "Diseased"),times=30))
pData(new.set) <-pdat
#let's pretend we have the output from the above experiment
#extract the data from the new.set object and transpose it
#rows are treatments, columns are "genes"
expressiondata <- as.data.frame(t(exprs(new.set)))
#need to extract the phenotypic information from the expression object
expressiondata$pheno <- pData(new.set)
names(expressiondata) <- make.names(names(expressiondata))
#let's take a look at what we have (it's big, lots of scrolling)
#glimpse(expressiondata)
graphdata <-
expressiondata %>%
select(X12136, pheno) %>%
ggplot(aes(x = pheno, y = X12136)) + geom_point()
#Ista's approach
library(tidyr)
x <- as.data.frame(new.set)
x$sample <- factor(1:nrow(x))
x <- gather(x, feature, intensity, -Condition, -sample)
ggplot(x, aes(x = sample, y = intensity, fill = Condition)) +
geom_boxplot() + coord_flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment