######################################################### ## Plots Demo ## ## Author: Han-Ming Wu (hmwu@stat.sinica.edu.tw) ## ## Institute of Statistical Science, Academia Sinica ## ## http://www.sinica.edu.tw/~hmwu/ ## ## 2006/07/25 ## ######################################################### ## Read Data setwd("C:\\Program Files\\R\\rw2001\\WorkingData") library(stats) ## in this test data, rows are samples, and columns are genes ## use command t(testdata) to transpose data if necessary test.matrix <- read.table("testdata.txt", header=TRUE) n <- dim(test.matrix)[1] p <- dim(test.matrix)[2]-2 test.data <- test.matrix[,3:(p+2)] name <- test.matrix[,1] ## group can be obtained by kmeans, hierarchical clustering ## and any other clustering algorithms group <- test.matrix[,2] groupID <- unique(group) no.group <- length(groupID) groupID.name <- c("group1", "group2", "group3", "group4", "group5", "group6") ## standardized data test.sdata <- (test.data-apply(test.data, 1, mean))/sqrt(apply(test.data, 1, var)) #Histogram for one selected gene hist(test.sdata[,1], br=12, col="lightblue", border="pink", labels = TRUE, main="Histogram", xlab="log ratio") #help Histogram ?hist #Boxplot boxplot(test.sdata, main="Boxplot for each gene") boxplot(test.sdata[,1]~group, names=groupID.name, main="Boxplot for groups of first gene") #Scatterplot matrix pairs(test.sdata, col=group, main="scatterplot matrix") pairs(test.sdata[,1:3], col=group, main="scatterplot matrix") ## Data Image test.image <- as.matrix(t(test.sdata[n:1,])) RGcol <- maPalette(low = "green", high = "red", k = 50) image(test.image, xlab="Genes", ylab="Samples", col = RGcol) ## Time Series Plots number <- 1:n par(mfrow=c(3,2)) for(i in 0:(no.group-1)){ ts.plot(t(test.sdata[number[group==i],]), xlab=groupID.name[i+1]) } ### Name: maPalette ### Title: Microarray color palette ### Aliases: maPalette ### Keywords: color ### Author: Sandrine Dudoit , Yee Hwa (Jean) Yang maPalette <- function(low = "white", high = c("green", "red"), mid=NULL, k =50) { low <- col2rgb(low)/255 high <- col2rgb(high)/255 if(is.null(mid)){ r <- seq(low[1], high[1], len = k) g <- seq(low[2], high[2], len = k) b <- seq(low[3], high[3], len = k) } if(!is.null(mid)){ k2 <- round(k/2) mid <- col2rgb(mid)/255 r <- c(seq(low[1], mid[1], len = k2), seq(mid[1], high[1], len = k2)) g <- c(seq(low[2], mid[2], len = k2), seq(mid[2], high[2], len = k2)) b <- c(seq(low[3], mid[3], len = k2), seq(mid[3], high[3], len = k2)) } rgb(r, g, b) }