Skip to content

Instantly share code, notes, and snippets.

@1beb
Created June 20, 2011 06:05
Show Gist options
  • Save 1beb/1035189 to your computer and use it in GitHub Desktop.
Save 1beb/1035189 to your computer and use it in GitHub Desktop.
Part VI: ggplot2 introduction
## Title: ggplot2 Introduction: Correlation Heatmap
## Description: This line by line analysis, provides an introduction to ggplot2. Correlation Heatmap
## Created by: Brandon Bertelsen: Research Manager, Credo Consulting Inc.
## Heatmap example courtesy of: http://learnr.wordpress.com/2010/01/26/ggplot2-quick-heatmap-plotting/
# Run correlations
e.new <- as.data.frame(cor(e[2:ncol(e)]))
# Reset rownames
e.new <- data.frame(row=rownames(e.new),e.new)
rownames(e.new) <- NULL
# Show
e.new
# Melt
e.new <- melt(e.new)
# Set options for a blank panel
po.nopanel <- list(opts(panel.background=theme_blank(),
panel.grid.minor=theme_blank(),
panel.grid.major=theme_blank()
))
# Plot correlation heatmap
ggplot(e.new, aes(reorder(row,-as.numeric(variable)), variable)) +
geom_tile(aes(fill=value)) +
scale_fill_gradient(breaks=seq(from=-1, to=1, by=0.25), low="white", high="steelblue") +
po.nopanel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment