服务热线
178 0020 3020
任务一:
> library(ggplot2)
> plot1<- ggplot(mtcars,aes(factor(cyl)))+geom_bar(aes(fill=factor(gear)),width = 0.6)+labs(title="Here is title",subtitle="Here is subtitle",caption="Here is caption",x="cyl")+scale_fill_discrete(name="gear")
plot1
> mytheme<- theme_classic()+theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),legend.position = "none",plot.caption = element_text(face = "bold.italic"))
> plot1+mytheme
任务二:
> library(ggplot2)
> library(latex2exp)
> myvolcano <- read.csv("/Users/LUCY/Desktop/科研狗R语言第二期/2-7/Volcanoplot/nature23643-s4.csv")
> myvolcano$significant <- ifelse((abs(log2(myvolcano$FC))>1 & abs(log2(myvolcano$q_value))>5),"YES","NO")
> myvolcano$mylabels <- ifelse((abs(log2(myvolcano$FC))>1 & abs(log2(myvolcano$q_value))>5),as.character(myvolcano$Gene.ID),NA)
> mysig <- subset(myvolcano,significant == "YES")
> ydrop = -0.6
> textdrop = 0.3
> myplot <- ggplot(myvolcano,aes(x = log2(FC) , y = -log2(q_value),size = significant)) +geom_point(col = "grey70",alpha = 1) + xlim(-2.5,2.7) +ylim(-0.8,15) +scale_size_manual(values = c(2,0)) +geom_point(data = mysig,aes(x = log2(FC),y = -log2(q_value),col = mylabels),size = 4,position = position_jitter(height = 0.1,width = 0)) +geom_text(aes(label = mylabels),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) +labs(title = "CMTM6 sgRNA2 vs Control",caption = "create by R2-14") +labs(x = expression(log[2])) +labs(x = expression(paste(log[2],"(fold change)")), y = expression(paste(-log[2],"(Q value)")))
> myplot
> myplot+mytheme
附件