Showing posts with label circle. Show all posts
Showing posts with label circle. Show all posts

Thursday, April 18, 2013

RG#79: Heatmap with overlayed circle (size and color)


set.seed (78888)
rectheat = sample(c(rnorm (10, 5,1), NA, NA), 150, replace = T)
circlefill =  rectheat*10 + rnorm (length (rectheat), 0, 3)
circlesize = rectheat*1.5 + rnorm (length (rectheat), 0, 3)
myd <- data.frame (rowv = rep (1:10, 15), columnv = rep(1:15, each = 10),
          rectheat, circlesize, circlefill)
          
          
require(ggplot2)
 pl1 <-  ggplot(myd, aes(y = factor(rowv),  x = factor(columnv))) +  geom_tile(aes(fill = rectheat)) +  scale_fill_continuous(low = "blue", high = "green")


  pl1  +      geom_point(aes(colour = circlefill,  size =circlesize))  +    scale_color_gradient(low = "yellow",   high = "red")+     scale_size(range = c(1, 20))+   theme_bw()


Sunday, April 7, 2013

RG#23: plot correlation: heat map and using ellipse

#data
set.seed(1234)
xm1 <- matrix(rnorm(100*10, rnorm(100, 0.5, 0.1)), nrow=100, ncol=10, byrow=FALSE)
xm2 <- matrix(rnorm(100*10, rnorm(100, 0.5, 0.1)), nrow=100, ncol=10, byrow=FALSE)
xm3 <- matrix(rnorm(100*10, rnorm(100, 0.5, 0.1)), nrow=100, ncol=10, byrow=FALSE)
dd <- cbind(xm1, xm2, xm3)

 cor <- cor(dd)# calculate correlation matrix


require(ellipse)
plotcorr(cor, outline = TRUE, col = "darkgreen", numbers = FALSE, type = "full", diag = FALSE)















#heatmap plot for the data using ggplot2.

require(ggplot2)
# first need to reshape data to long form
require(reshape)
cor.melt <- data.frame(melt(cor) )
ggplot(cor.melt , aes(x=X1,y=X2, z= value)) + geom_tile(aes(fill= value)) + scale_fill_gradient(low="red", high="green") + theme_bw()