Created
March 25, 2013 21:21
-
-
Save Ram-N/5240881 to your computer and use it in GitHub Desktop.
Correlation Heatmaps in ggplot2 with custom colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set up a coloring scheme using colorRampPalette | |
red=rgb(1,0,0); green=rgb(0,1,0); blue=rgb(0,0,1); white=rgb(1,1,1) | |
RtoWrange<-colorRampPalette(c(red, white ) ) | |
WtoGrange<-colorRampPalette(c(white, green) ) | |
p <- p + scale_fill_gradient2(low=RtoWrange(100), mid=WtoGrange(100), high="gray") | |
p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) | |
library(ggplot2) | |
library(reshape2) | |
#help(package = "ggplot2") | |
data(movies) | |
movieGenres <- movies[c(18:23)] #subset to 6 genres | |
cor(movieGenres) # 6x6 cor matrix | |
#ggplot likes the data 'melted' one value per row | |
m <-melt(cor(movieGenres)) | |
p <- ggplot(data=m, aes(x=Var1, y=Var2, fill=value)) + geom_tile() | |
p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getwd() | |
rm(list = ls()) | |
library(ggplot2) | |
library(reshape2) | |
#help(package = "ggplot2") | |
data(movies) | |
movieGenres <- movies[c(18:23)] #subset to 6 genres | |
cor(movieGenres) # 6x6 cor matrix | |
#ggplot likes the data 'melted' one value per row | |
m <-melt(cor(movieGenres)) | |
p <- ggplot(data=m, aes(x=Var1, y=Var2, fill=value)) + geom_tile() | |
p | |
#set up a coloring scheme using colorRampPalette | |
red=rgb(1,0,0); green=rgb(0,1,0); blue=rgb(0,0,1); white=rgb(1,1,1) | |
RtoWrange<-colorRampPalette(c(red, white ) ) | |
WtoGrange<-colorRampPalette(c(white, green) ) | |
## | |
p <- p + scale_fill_gradient2(low=RtoWrange(100), mid=WtoGrange(100), high="gray") | |
p | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment