-
Notifications
You must be signed in to change notification settings - Fork 53
Kun Wang edited this page Nov 7, 2020
·
8 revisions
test1=rpois(1e6,1.34) # lambda=1.47
test2=as.data.frame(table(test1))
test3=as.data.frame(spline(test2$test1,test2$Freq))
ggplot(test2,aes(test1,Freq))+geom_point()+geom_line(data=test3,aes(x=x,y=y))
library(MASS)
library(ggplot2)
library(viridis)
get_density <- function(x, y, ...) {
dens <- MASS::kde2d(x, y, ...)
ix <- findInterval(x, dens$x)
iy <- findInterval(y, dens$y)
ii <- cbind(ix, iy)
return(dens$z[ii])
}
a=read.csv("test.csv",header=T)
b=na.omit(a)
b$density=get_density(b$pi.pdav,b$pi.prot,n=100)
ggplot(b) + geom_point(aes(pi.pdav, pi.prot, color = density)) + scale_color_viridis(option = "D")
m=quantile(b$pi.pdav,0.99)
n=quantile(b$pi.prot,0.99)
l=cor.test(b$pi.pdav,b$pi.prot)
line=paste("rho=",signif(l$estimate,3),", pvalue=",signif(l$p.value,3))
ggplot(b) + geom_point(aes(pi.pdav, pi.prot, color = density)) + scale_color_viridis(option = "D")+geom_abline()+geom_vline(xintercept=m,color="red")+geom_hline(yintercept=n,color="red")+xlim(0,0.15)+ylim(0,0.15)+theme_classic()+geom_text(x=0.05,y=0.15,label=line) # ** means p<0.001 *** means p<2.2e-16; xlim and ylim should be notified
num=1000;
newdata=data[sample(nrow(data),num),]
a=read.table('07.corBetweenSpecies.pl.out',header=T)
x=c('muscle','heart','brain','liver','jaw','gill','spinalcord','skin','lung')
a$tissue=factor(a$tissue,levels=x)
ggplot(a,aes(tissue,cor))+geom_boxplot()+theme_classic()
library(hexbin)
library(RColorBrewer)
rf <- colorRampPalette(rev(brewer.pal(11,'Spectral')))
a=read.table('brain.txt',header=T)
a$lung.bichir.len=a$lungfish.len/a$bichir.len
a$lung.bichir.rpkm=a$lungfish.rpkm/a$bichir.rpkm
b=subset(a,a$bichir.rpkm>0)
b=subset(b,b$lungfish.rpkm>0)
c=b
c$lung.bichir.len=log10(c$lung.bichir.len)
c$lung.bichir.rpkm=log10(c$lung.bichir.rpkm)
plot(hexbin(x=c$lung.bichir.len,y=c$lung.bichir.rpkm,xbins=60),colramp=rf)