千家信息网

R语言如何绘制类似于箱线图的散点图

发表于:2024-09-26 作者:千家信息网编辑
千家信息网最后更新 2024年09月26日,这篇文章主要为大家展示了"R语言如何绘制类似于箱线图的散点图",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"R语言如何绘制类似于箱线图的散点图"这篇文章吧。
千家信息网最后更新 2024年09月26日R语言如何绘制类似于箱线图的散点图

这篇文章主要为大家展示了"R语言如何绘制类似于箱线图的散点图",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"R语言如何绘制类似于箱线图的散点图"这篇文章吧。

作图需要整备两个文件,即各差异组合差异基因的差异倍数,如下所示:

log2FC          Group-0.003569046    SR58-1-0.033401692    SR58-1-0.00595792     SR58-1-0.126160677    SR58-1-0.003569046    SR58-10.062951504     SR58-1-0.085369416    SR58-10.061838866     SR58-1-0.006699121    SR58-1-0.006699121    SR58-10.565357698     SR58-1-1.478225114    SR58-1-0.081035817    SR58-1-0.103533775    SR58-1-0.143437623    SR58-1-0.103533775    SR58-1-0.143437623    SR58-1-0.095751056    SR58-10.358148301     SR58-1-0.187767352    SR58-10.389438905     SR58-1

绘图用的是R脚本,代码为:

library(ggplot2)library('getopt');spec = matrix(c('help' , 'h', 0, "logical","for help",'input1' , 'i', 1, "character","input the abuance of tax in each sample ,required",'input2' , 's', 1, "character","input the abuance of tax in each sample ,required",#'row' , 'r' , 1 , "character","row name,required",'name' , 'n', 1, "character","photo name"), byrow=TRUE, ncol=5);opt = getopt(spec);print_usage <- function(spec=NULL){cat(getopt(spec, usage=TRUE));q(status=1);}if ( !is.null(opt$help) ) { print_usage(spec) }if ( is.null(opt$input1) ){ print_usage(spec) }if ( is.null(opt$input2) ){ print_usage(spec) }if ( is.null(opt$name) ){ opt$name = "Co-occurrence_network" }#读入数据point1 <- read.table(opt$input1,sep="\t",header = TRUE,comment.char = "")point2 <- read.table(opt$input2,sep="\t",header = TRUE,comment.char = "")#分别取中位数median1 = median(point1$log2FC, na.rm = FALSE)median2 = median(point2$log2FC, na.rm = FALSE)print(median1)print(median2)#行合并point = rbind(point1,point2)p <- ggplot(point, aes(x=Group, y=log2FC)) + geom_point(size=0.5)+geom_segment(aes(x=0.95,y=median1,xend=1.05,yend=median1))+geom_segment(aes(x=1.95,y=median2,xend=2.05,yend=median2))+geom_hline(aes(yintercept=0), colour="#000000", linetype="dashed")+theme(######取消默认的背景颜色方框等panel.background = element_rect(fill = "transparent",colour = "black"), panel.grid.minor = element_blank(), panel.grid.major = element_blank(),plot.background = element_rect(fill = "transparent",colour = "black"))#输出文件名称png_name=paste(opt$name, ".png", sep="")pdf_name=paste(opt$name, ".pdf", sep="")#输出pdf格式图片pdf(pdf_name,width =3,height = 3)print(p)dev.off()#输出png格式图片png(png_name,width =2000,height =2000,res = 500,units = "px")print(p)dev.off()

以上是"R语言如何绘制类似于箱线图的散点图"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0