火山图
代码语言:javascript复制diff0 = read.table("volcano_plot.txt",sep="t",header=T)
P.value = diff0$adj.P.Val
FC = diff0$logFC
df <- data.frame(P.value,FC)
df$threshold = as.factor(abs(df$FC) > log(1.5,2) & df$P.value < 0.01)
levels(df$threshold) = c('#f1f1f3','red')
df$logp = -log10(df$P.value)
利用base系统绘图
代码语言:javascript复制#using base
plot(x = df[,2],y = df[,4], pch=16, col=df$threshold,
xlab="Fold change", ylab="-Log10(Pvalue)",
cex=0.2, main="Volcano Plot")
abline(v=c(-log(1.5,2),log(1.5,2)), h=-log10(0.01),col="green")
利用ggplot2绘图
代码语言:javascript复制#using ggplot2
library(ggplot2)
ggplot(data=df,aes(x=FC,y=-log10(P.value)))
geom_point(colour=df$threshold)
QQ图
代码语言:javascript复制#生成100个正态分布的随机数
data = rnorm(100,0,1)
#生成柱状图,查看所生成随机数的分布情况
hist(data,10)
代码语言:javascript复制#利用经验累积分布函数(empirical cumulative distribution function, eCDF)
#来评价数据分布的情况
data.cdf = ecdf(data)
plot(data.cdf)
代码语言:javascript复制#QQ-plot 正态分布
#50 numbers
data50 = rnorm(100,0,1)
hist(data50,20)
qqnorm(data50, pch=16)
qqline(data50, pch=16, col="red")
代码语言:javascript复制#100 numbers
data100 = rnorm(100,0,1)
hist(data100,20)
qqnorm(data100, pch=16)
qqline(data100, pch=16, col="red")
代码语言:javascript复制#150 numbers
data150 = rnorm(150,0,1)
hist(data150,20)
qqnorm(data150, pch=16)
qqline(data150, pch=16, col="red")
代码语言:javascript复制#1000 numbers
data1000 = rnorm(1000,0,1)
hist(data1000,20)
qqnorm(data1000, pch=16)
qqline(data1000, pch=16, col="red")
代码语言:javascript复制#put the figures all together to see the change and the differents
nf <- layout(matrix(c(1,2,3,4),2,2,byrow=TRUE), c(2,2), c(2,2), TRUE)
layout.show(nf)
#fig1
qqnorm(data50, pch=16, main="QQ-plot for 100 numbers")
qqline(data50, pch=16, col="red")
#fig2
qqnorm(data100, pch=16, main="QQ-plot for 200 numbers")
qqline(data100, pch=16, col="red")
#fig3
qqnorm(data150, pch=16, main="QQ-plot for 500 numbers")
qqline(data150, pch=16, col="red")
#fig4
qqnorm(data1000, pch=16, main="QQ-plot for 1000 numbers")
qqline(data1000, pch=16, col="red")
#Shapiro-Wilk test of normality
shapiro.test(data)