服务热线
178 0020 3020
作业1:
library(tibble)
library(ggplot2)
mt=rownames_to_column(mtcars,var="group")
mt=mt[1:5,]
mytheme=theme_bw()+theme(panel.border = element_blank(),panel.grid.major = element_blank(),panel.grid.minor = element_blank(),axis.line = element_line(colour = "black"),legend.position = "none")
ggplot(mt,aes(x=group,y=mpg))+geom_bar(stat="identity",fill="red")+mytheme+ggtitle("R2-21")
作业2:
mydata=read.csv("R2-第七期作业-火山图 (1)/nature23643-s4.csv",head=T)
mydata$id=mydata$Gene.ID
mydata$q_value=-log2(mydata$q_value)
mydata$FC=log2(mydata$FC)
mydata$threshold=as.factor(ifelse(mydata$q_value>5,ifelse(abs(mydata$FC)>1,"yes","not"),"not"))
yes=subset(mydata,mydata$threshold == "yes")
not=subset(mydata,mydata$threshold == "not")
ggplot()+mytheme+geom_point(data=not,aes(x=FC,y=q_value),color="grey")+geom_point(data=yes,aes(x=FC,y =q_value,color=id),size=2)+xlim(-3,3)+geom_text(data=yes,aes(x=FC,y=q_value,label=yes$id),vjust=2)+geom_vline(xintercept =0,lty=4,col="black")+labs(x = expression(paste(log[2],"(fold change)")),y = expression(paste(-log[2],"(Q value)")))+annotate("segment", x = 1 , xend = 2.5, y = ydrop,yend = ydrop ,color = "black", size = 0.5,arrow = arrow(angle = 18,ends = "last",type = "closed")) +annotate("segment", x = -1 , xend = -2.5, y = ydrop,yend = ydrop ,color = "black",size = 0.5,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)+ggtitle("R2-21")
附件