查看原文
其他

富集图形添加注释美化

JunJunLab 老俊俊的生信笔记 2023-06-15


岁月静好是片刻,一地鸡毛是日常

1引言

看看我们如何添加一些注释来给我们的富集图形进行美化。

2读取数据

简单的富集结果:

library (ggplot2)
library(grid)
library(ggsci)

df1 <- read.delim('goTest.txt',header = T)
df1$log10PValue <- -log10(df1$PValue)

# check
head(df1,3)
#                                 Term      PValue log10PValue
# 1 positive regulation of mesenchymal cell proliferation 0.002338937    2.630981
# 2                                   signal transduction 0.003193134    2.495783
# 3                                     blood coagulation 0.007611012    2.118558

3绘图

绘制基本图形看看:

# order
df1$Term <- factor(df1$Term,levels = rev(df1$Term))

# Plot
pgo <-
ggplot(df1,aes(x = log10PValue,y = Term)) +
  geom_point(aes(size = log10PValue,
                 color = log10PValue)) +
  scale_color_gradient2(low = 'blue',mid = 'green',high = 'red',
                        name = '',midpoint = 2.1) +
  scale_y_discrete(position = 'right') +
  scale_x_continuous(breaks = seq(0,2.8,0.4),limits = c(0,2.8)) +
  theme_grey(base_size = 14) +
  theme(legend.position = 'left',
        plot.margin = margin(t = 1,r = 1,b = 1,l = 1,unit = 'cm'),
        aspect.ratio = 2.5
        ) +
  coord_cartesian(clip = 'off') +
  ylab('')

pgo

然后添加一些注释,比如文字,矩形,线段等等:

# colors
col <- c('#F5F0BB','#C4DFAA','#90C8AC')
colr <- c('#573391','#357C3C','#EF6D6D')
text <- c('Term one','Term two','Term three')

# loop add points
for (i in 1:3)  {
  pgo <- pgo +
    # rect
    annotation_custom(
      grob = rectGrob(gp = gpar(col = 'black',fill = col[i],
                                lty = 'dashed',lwd = 1)),
      xmin = unit(3,'native'),xmax = unit(8.5,'native'),
      ymin = unit(i*5 + 0.5 - 5,'native'),ymax = unit(i*5 + 0.5,'native')) +
    # segment right
    annotation_custom(
      grob = segmentsGrob(gp = gpar(col = col[i],
                                    lwd = 5)),
      xmin = unit(8.6,'native'),xmax = unit(8.6,'native'),
      ymin = unit(i*5 + 0.5 - 5,'native'),ymax = unit(i*5 + 0.5,'native')) +
    # segment left
    annotation_custom(
      grob = segmentsGrob(gp = gpar(col = colr[i],
                                    lwd = 5)),
      xmin = unit(-0.3,'native'),xmax = unit(-0.3,'native'),
      ymin = unit(i*5 + 0.5 - 5,'native'),ymax = unit(i*5 + 0.5,'native')) +
    # text
    annotation_custom(
      grob = textGrob(gp = gpar(col = 'black',
                                cex = 2),
                      label = text[i],
                      check.overlap = T,
                      rot = 270),
      xmin = unit(8.8,'native'),xmax = unit(8.8,'native'),
      ymin = unit(i*5 - 2.5,'native'),ymax = unit(i*5 - 2.5,'native'))

}

# print
pgo

4结尾

与其这样 繁琐 的添加,有没有一种可能,搞个包 更加便捷, 随心所欲的 添加个性化注释呢?





  老俊俊生信交流群 (微信交流群需收取20元入群费用(防止骗子和便于管理))



老俊俊微信:


知识星球:



今天的分享就到这里了,敬请期待下一篇!

最后欢迎大家分享转发,您的点赞是对我的鼓励肯定

如果觉得对您帮助很大,赏杯快乐水喝喝吧!




  





R 中的控制结构

ggpolar 绘制极坐标图形

transPlotR 优雅的绘制基因转录本结构

ggarchery 添加个性化箭头

scRNAtoolVis 0.0.3 版本更新

customize 你的 GSEA 图

GseaVis 优雅的可视化 GSEA 富集结果

GSEA 图是如何画出来的? (源码解析)

clusterProfiler 的可视化大全

clusterProfiler 做 GSEA 富集分析

◀..

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存