Category Archives: R

barplot with different colors

rm(list=ls())
expression = runif(20)
expression = expression[order(expression,decreasing = T)]
types = c(rep(1,times=10),rep(2,times=10))
data = data.frame(expression=expression,types=types)
names = paste(‘exon_’,1:20,sep=””)
rownames(data)=names
barplot(data$expression,col = c(“deepskyblue”,”gray”)[as.factor(data$types)],horiz=F,border = F,las=2,names=rownames(data),xlab=”Splicing genes”,ylab=”conservation scores”,cex.names = 0.6,cex.lab = 1.5)

An example script of creating a heatmap using the heatmap.2 function in R

 

# Just copy all below into R to test

# Notes: the styles of “double quotes” when copied may change and make the script not run normally, but you can manually change the “double quotes”.

rm(list=ls())
require(gplots)
X=matrix(rnorm(120),nrow=20)
breaks = 20 # number of colors
my_palette <- colorRampPalette(c(“green”,”red”))(n =breaks-1) # self-define and discretize color maps
heatmap.2(X,Colv = NA,col=my_palette,breaks = breaks,density.info=”none”,trace = “none”,scale=”none”)

Venn diagram in R

# personal notes

library(VennDiagram)
data=list(A=c(1,2,3,4,5,6),B=c(3,4,5,6,7),C=c(5,6,7,8,9,10))    # demo data
venn.diagram(data,”vennFigure.tiff”,fill = c(“cornflowerblue”, “green”, “yellow”))  # venn diagram saved to a file