install.packages("plotly")
install.packages("ggplot2")
install.packages("ggpubr")
library(ggplot2)
library(ggpubr)
ifelse(dir.exists("opFig"),FALSE,dir.create("opFig"))#建一个opFig的文件夹,后续你生成的所有图片都会出现在这里
drug <- as.data.frame(drug)
for (dr in rownames(drug)) {#如果给定药物 把循环rownames(drug)换成你的药物向量,比如for (dr in "tamoxifen")
tit <- paste0("R:",round(plotly::filter(output,Drug == dr)[,3],2),",p value = ",round(plotly::filter(output,Drug == dr)[4],3))
colnames(drug) == colnames(exp)
df <- rbind(drug[dr,],exp) %>% t() %>% as.data.frame()
colnames(df)[1] <- c("drug")
p <- ggplot(data = df, aes(x = drug, y = MSI1)) + #数据映射
geom_point(alpha = 0.6,shape = 19,size=3,color="#DC143C") +#散点图,alpha就是点的透明度
#geom_abline()+
labs(title = tit)+
geom_smooth(method = lm, formula = y ~ x,aes(colour = "lm"), size = 1.2,se = T)+
scale_color_manual(values = c("#808080")) + #手动调颜色c("#DC143C","#00008B", "#808080")
theme_bw() +#设定主题
theme(axis.title=element_text(size=15,face="plain",color="black"),
axis.text = element_text(size=12,face="plain",color="black"),
legend.position = "none",
panel.background = element_rect(fill = "transparent",colour = "black"),
plot.background = element_blank(),
plot.title = element_text(size=15, lineheight=.8,hjust=0.5, face="plain"),
legend.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt"))+
ylab(paste0("Activity z scores of ",dr)) + #expression的作用就是让log10的10下标
xlab(paste0("The expression of ",gene))
ggsave(filename = paste0("opFig/",gene,"-",dr,"-cor.pdf"),plot = p,width = 5,height = 5)
}
出图是这样的:举个栗子