服务热线
178 0020 3020
library(ggplot2)
plot1<-ggplot(mtcars,aes(x=factor(cyl),fill=factor(gear)))+
geom_bar(width = 0.5)+
labs(title = "Here is title", subtitle = "Here is subtitle", caption = "R2-12", x = "cyl")
plot1
#creat a new theme
theme_zz <- theme_classic() +
theme(panel.background=element_rect(fill='white'),#背景白色
panel.grid = element_blank(),#消除网格
legend.position = "",#消除坐标
axis.line = element_line(color = "black"),#axis
plot.caption = element_text(face = "bold.italic"))#change the font
#use the theme_zz
plot1+theme_zz
第一种做法,参考发布任务
library(latex2exp)
myvolcano<-read.table("nature23643-s4.csv",header = T,sep = ",")
fix(myvolcano)#fix gene.ID
attach(myvolcano)
myvolcano$significant<-ifelse(abs(log2(FC))<1,"not","yes")
myvolcano$lables<-ifelse(abs(log2(FC))<1,NA,as.character(gene.ID))
mysig<-subset(myvolcano,significant=="yes")
mysig
ydrop = -0.6
textdrop=0.3
#volcano
p1<-ggplot(data = myvolcano,aes(x=log2(FC),y=-log2(q_value),size=significant))+
geom_point(color="grey",alpha=0.4)+
xlim(c(-3,3))+ylim(c(-1,16))+
scale_size_manual(values = c(2,0))+
geom_vline(xintercept = c(0),lty=4,col="black",lwd=0.5)+
geom_hline(yintercept = -log2(1/32),lty=4,col="red",lwd=0.5)+
#overlap
geom_point(data = mysig,aes(x=log2(FC),y=-log2(q_value),color=lables),size=4)+
geom_text(aes(label=lables),size=3,hjust=0,vjust=-1,col="black",fontface="italic")+
annotate("segment", x = 1,xend = 2.5,y = ydrop,yend = ydrop,color = "black",
size = 1,arrow = arrow(angle = 18,ends = "last",type = "closed")) +
annotate("segment",x = -1,xend = -2.5,y = ydrop,yend = ydrop,color = "black",
size = 1,arrow = arrow(angle = 18,ends = "last",type = "closed")) +
annotate("text",x = 1.7,y = textdrop,label = "Upregulated",size = 4.5) +
annotate("text",x = -1.7,y = textdrop,label = "Downregulated",size = 4.5)
p1+theme_zz+ggtitle("R2-12")
第二种参考R2-21想法
volcano_zz<-read.table("nature23643-s4.csv",header = T,sep = ",")
View(volcano_zz)
fix(volcano_zz)#fix gene.ID
volcano_zz$th<-as.factor(ifelse(-log2(volcano_zz$q_value)>4.33&
abs(log2(volcano_zz$FC))>1,"yes","not"))
yes<-subset(volcano_zz,th=="yes")
not<-subset(volcano_zz,th=="not")
np<-ggplot(not,aes(x=log2(FC),y=-log2(q_value)))+
geom_point(color="grey")+
geom_point(data=yes,aes(x=log2(FC),y=-log2(q_value),color=gene.ID,size=3))+
geom_text(data=yes,aes(label=gene.ID),size=3,hjust=0,vjust=-1,col="black",fontface="italic")+
xlim(-2.5,2.5)+
ylim(-1,14)+
annotate("segment",x=-1,xend = -2.5,y=-0.7,yend = -0.7,color="black",size=1,
arrow=arrow(angle = 20,ends = "last",type = "closed"))+
annotate("segment",x=1,xend = 2.5,y=-0.7,yend = -0.7,color="black",size=1,
arrow=arrow(angle = 20,ends = "last",type = "closed"))+
annotate("text",x=-1.5,y=0,label="Downregulated")+
annotate("text",x=1.5,y=0,label="Upregulated")+
geom_vline(xintercept = 0,lty=4,col="black",lwd=0.5)+
geom_hline(yintercept = -log2(0.05),lty=4,col="black",lwd=0.5)
np+theme_zz+ggtitle("R2-12_volcano")
附件