Saturday, April 13, 2013

RG#56: heatmap plot of categorical variables



#data 
datf <- data.frame(indv=factor(paste("ID", 1:20),
    levels =rev(paste("ID", 1:20))), matrix(sample(LETTERS[1:7], 400, T), ncol = 20))



library(ggplot2); 
library(reshape2)
# converting data to long form for ggplot2 use

datf1 <- melt(datf, id.var = 'indv')

ggplot(datf1, aes(variable, indv)) + geom_tile(aes(fill = value),
   colour = "white")  +   scale_fill_manual(values= rainbow (7))



1 comment:

  1. Supose I would like to have each variable in a different colour scheme. How would I do that?

    ReplyDelete

Note: Only a member of this blog may post a comment.