R语言学习笔记separate {tidyr},绘制气泡图

separate {tidyr}的功能是使用正则表达式分隔符将字符列分隔成多个列。给定正则表达式或字符位置向量,separate()将单个字符列转换为多个列。这个功能在生信分析中用到的频率太多了,比如TCGA的基因ID转换中ENSG00000000003.13转换成ENSG00000000003,比如对TCGA样本的ID切割等等。
在这里插入图片描述

在这里插入图片描述

separate(data, col, into, sep = “[1]+”, remove = TRUE, convert = FALSE, extra = “warn”, fill = “warn”, …)

rm(list = ls())#一键清空
library(tidyr)
library(dplyr)
library(ggplot2)```

```r
kegg <- read.csv("C:/Users/xxy/kangyuan/服务器/JZ20231023/M1 vs M2/JZ.M1.M2.high.KEGG.csv",header=TRUE)
kegg <- read.csv("C:/Users/xxy/kangyuan/服务器/JZ20231023/M1 vs M2/JZ.M1.M2.high.GO.csv",header=TRUE)```

```r
#【kegg拆分】
kegg = separate(kegg,Term, sep=":",into=c("ID","Description"))
kegg_top15 <- head(kegg,n=15)

#【go拆分】
kegg = separate(kegg,Term, sep="~",into=c("ID","Description"))
kegg_top15 <- head(kegg,n=15)```

```r#DAVID格式【表中%代表gene ratio,表需拆分!】
###DAVID_GO
kegg_plot_top15 <- ggplot(data = kegg_top15,aes(x=X.,y =Description))+
  geom_point(aes(size=Count,color=-1*log10(PValue)))+
  scale_color_gradient(low="green",high = "red")+
  labs(color=expression(-log[10](PValue)),size="Count",x="enrichment factor",y=" GO term ")+
  theme_bw()+  
  theme(axis.title.x = element_text(size = 10,color = "black"),
        axis.title.y = element_text(size = 10,color = "black"),
        axis.text.x = element_text(size=10,color = "black"),
        axis.text.y = element_text(size = 10,color = "black"))

ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.tiff")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.png")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.pdf")

###DAVID_KEGG
kegg_plot_top15 <- ggplot(data = kegg_top15,aes(x=X.,y =Description))+
  geom_point(aes(size=Count,color=-1*log10(PValue)))+
  scale_color_gradient(low="green",high = "red")+
  labs(color=expression(-log[10](PValue)),size="Count",x="enrichment factor",y=" Pathways ")+
  theme_bw()+  
  theme(axis.title.x = element_text(size = 15,color = "black"),
        axis.title.y = element_text(size = 15,color = "black"),
        axis.text.x = element_text(size=15,color = "black"),
        axis.text.y = element_text(size = 15,color = "black"))

ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.tiff")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.png")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.pdf")```






  1. :alnum: ↩︎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值