R

1. Using R to draw a Heatmap from Microarray Data

2. 画VENN图

> library(VennDiagram)
Loading required package: grid
Warning message:
package 'VennDiagram' was built under R version 2.13.0
> x <- c(1,3,5,7,9,11,17,19,21,23,25,29,31,33,37,39,41,47,49,51,57,59)
> y <- c(1,3,5,7,13,17,19,21,23,25,27,29,31,33,45,47,51)
> z <- c(1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,55,57,59,61)
> venn.diagram(list(X=x,Y=y,Z=z),fill=c("red","blue","yellow"),"out.tiff")
[1] 1


输出1表示画图成功,生成的结果是out.tiff,这个文件在你的R工作目录下。

3. R barplot

library(ggplot2)
library(ggpubr)
mypcr2<- read.table("mypcr3.txt", header = T, sep = "\t")
p <- ggplot(mypcr2, aes(Gene,Gene.Expression,fill = Gender))
p + geom_bar(position = 'dodge', stat = 'summary', fun.y = 'mean') +
geom_errorbar(stat = 'summary', position = 'dodge', width = 0.9) +
geom_point(aes(x = Gene), shape = 21, position = position_dodge(width = 1))+
stat_compare_means(aes(group=Gender), label = "p.format")

数据格式:
Gender Gene.Expression Gene
Male_Brain 5.32 zgc:114181
Male_Brain 4.11 zgc:114181
Male_Brain 2.12 zgc:114181
Female_Brain 4.12 zgc:114181
Female_Brain 6.63 zgc:114181
Female_Brain 3.05 zgc:114181
Male_Brain 7.32 zgc:114181
Male_Brain 4.11 zgc:114181
Male_Brain 3.12 zgc:114181
Female_Brain 0.12 zgc:114181
Female_Brain 6.63 zgc:114181
Female_Brain 3.05 zgc:114181
Male_Brain 7.63 c3a.1
Male_Brain 6.09 c3a.1
Male_Brain 3.35 c3a.1
Female_Brain 6.24 c3a.1
。。。

4. 好看的图

library(RColorBrewer)
library(reshape2)
a=rnorm(100, mean=1)
b=rnorm(100, mean=0, sd=1)
ab=data.frame(a,b)
melt=melt(ab)
bpColor=brewer.pal(4, 'RdBu')
boxplot(melt$value ~ melt$variable, notch=F, col=c(bpColor[1], bpColor[4]), outline=F, varwidth=T)
stripchart(melt[melt$variable == "a", "value"] ~ melt[melt$variable == "a", "variable"], add=T, vertical=T, pch=21, bg=c(bpColor[2]), method='jitter', jitter=0.03)
stripchart(melt[melt$variable == "b", "value"] ~ melt[melt$variable == "b", "variable"], add=T, vertical=T, pch=21, bg=c(bpColor[3]), method='jitter', jitter=0.03)

5. Boxplot单独分组代码:
library(ggplot2)
library(ggpubr)
mypcr2<- read.table("mypcr3.txt", header = T, sep = "\t")
p <- ggboxplot(mypcr2, x="Gender", y="Gene.Expression", color = "Gender",
palette = "jco", add = "jitter", facet.by = "Gene", short.panel.labs = FALSE)
p+stat_compare_means(label = "p.format", label.x = 1.5)

6. boxplot显示在一张图上的代码

library(ggplot2)
library(ggpubr)
mypcr2<- read.table("mypcr3.txt", header = T, sep = "\t")
p <- ggboxplot(mypcr2, x="Gene", y="Gene.Expression", color = "Gender",
palette = "npg", add = "jitter")
p+stat_compare_means(aes(group=Gender), label = "p.format")

7. 柱状图代码
library(ggplot2)
library(ggpubr)
library(ggpubr)
mypcr2<- read.table("mypcr3.txt", header = T, sep = "\t")
ggbarplot(mypcr2, x="Gene", y="Gene.Expression", add = "mean_se", color = "Gender",
palette = "npg", position = position_dodge(0.8))+
stat_compare_means(aes(group=Gender), label = "p.format", label.y = 9)