Skip to content

Instantly share code, notes, and snippets.

@skurscheid
Created April 27, 2017 06:30
Show Gist options
  • Save skurscheid/7631656e8017b812d66394ccdff35da1 to your computer and use it in GitHub Desktop.
Save skurscheid/7631656e8017b812d66394ccdff35da1 to your computer and use it in GitHub Desktop.
creates a "heatmap" from pre-processed qPCR data using ggplot2 geom_tile()
require(gdata)
require(dtplyr)
require(ggplot2)
# setwd("~/OneDrive/Documents/ANU/Tremethick Lab/Students/Yichen - BSc Hons/")
# load the Excel sheet
# this presumes that the file is in the current working directory, you can check with getwd()...
dat <- read.xls("CTA HL summary.xlsx")
# tidy up and reformat data for plotting
colnames(dat) <- c("cluster", "gene", "L1236", "L1236_sd", "L428", "L428_sd", "HDLM-2", "HDLM-2")
dat <- as.data.table(dat[-1,])
dat[1:21, "cluster"] <- "cluster1"
dat[22:32, "cluster"] <- "cluster2"
# this final step will make the data conform to ggplot2 requirements
dat <- melt(dat[,c("cluster", "gene", "L1236", "L428", "HDLM-2")],
id.vars = c("cluster", "gene"),
measure.vars = c("L1236", "L428", "HDLM-2"))
dat[which(dat$value == "undetectable"), "value"] <- "NA"
dat$value <- as.numeric(dat$value)
summary(dat$value)
dat$gene <- drop.levels(dat$gene)
dat$gene <- reorder.factor(dat$gene, new.order = as.character(dat$gene[1:32]))
colvec <- c("purple", "blue")[match(dat$cluster[1:32], c("cluster1", "cluster2"))]
# plotting
plot1 <- ggplot(dat, aes(x = variable, y = gene, group = cluster)) +
geom_tile(aes(fill = value), colour = "white") +
scale_fill_gradient(low = "green", high = "red", na.value = "lightgrey") +
theme(axis.text.y = element_text(colour=colvec))
plot1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment