温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2022-03-10 11:09:02 来源:亿速云 阅读:384 作者:小新 栏目:开发技术

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

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

log2FC          Group
-0.003569046    SR58-1
-0.033401692    SR58-1
-0.00595792     SR58-1
-0.126160677    SR58-1
-0.003569046    SR58-1
0.062951504     SR58-1
-0.085369416    SR58-1
0.061838866     SR58-1
-0.006699121    SR58-1
-0.006699121    SR58-1
0.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-1
0.358148301     SR58-1
-0.187767352    SR58-1
0.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语言如何绘制类似于箱线图的散点图”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI