前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >🤣 easylabel | 完美拯救手残党不会标注突出重点!(Label!~ Label!~)

🤣 easylabel | 完美拯救手残党不会标注突出重点!(Label!~ Label!~)

作者头像
生信漫卷
发布2023-02-24 14:18:08
5630
发布2023-02-24 14:18:08
举报
文章被收录于专栏:R语言及实用科研软件

1写在前面

我们在画图的时候经常需要标记某个值, 如散点图中的某个具体的点, 火山图中的某个基因, 但对于代码不太熟悉的小白来说, 还是有一定难度的.🤪 本期和大家介绍一个基于shiny轻松进行label的包, 即easylabel包, 轻松实现交互式label, 麻麻再也不用担心你的画图标记啦.😗

2用到的包

代码语言:javascript
复制
rm(list = ls())
# devtools::install_github("myles-lewis/easylabel")
library(easylabel)
library(tidyverse)
library(qvalue)
library(AnnotationDbi)
library(org.Hs.eg.db)
library(ggstatsplot)
library(plotly)

3散点图

3.1 初步绘图

我们先简单画个散点图, 试着标记一下吧。

这里是可以交互的,大家直接点一下就标记了哦。🤩

代码语言:javascript
复制
dat <- movies_long

dat %>%
  easylabel(x = 'length', 
            y = 'rating',
            labs = 'title',
            colScheme = 'royalblue')

3.2 简单导出文件

接着在底部可以找到输出按钮,点击后导出你需要的格式吧~😏


3.3 导出为ploty对象

我们也可以通过设置output_shiny = F, 不激活shiny而直接导出为ploty对象, 依然是可交互的哦, 请随意移动。🤓

代码语言:javascript
复制
p1 <- easylabel(dat, 
                x = 'length', y = 'rating', col = 'genre', 
                startLabels = dat$rating[dat$year == 1994], 
                output_shiny = F) %>% 
  layout(yaxis = list(zeroline = F))

p2 <- easylabel(dat, 
                x = 'length', y = 'votes', col = 'genre', 
                startLabels = dat$votes[dat$year == 1994], 
                output_shiny = F) %>% 
  layout(yaxis = list(zeroline = F))

plotly::subplot(p1, p2, nrows = 2, shareY = T, titleX = T, margin = 0.05)

4美化细节

接着我们做一些细节的美化, 支持colour, shape, size等设置。😉

4.1 colour

代码语言:javascript
复制
easylabel(dat, 
          x = 'length', y = 'budget',
          col = 'genre', alpha = 0.6,
          output_shiny = F,
          labs = 'title',
          main = 'colour')%>% 
  layout(yaxis = list(zeroline = F))

4.2 shape

代码语言:javascript
复制
  dat[1:100,] %>% 
  easylabel(
          x = 'length', y = 'rating', 
          col = 'genre', alpha = 0.6,
          shape = 'mpaa', shapeScheme = 21,
          output_shiny = F,
          labs = 'title',
          main = 'shape') %>% 
  layout(yaxis = list(zeroline = F))

4.3 size

代码语言:javascript
复制
  dat[1:100,] %>% 
  easylabel(
          x = 'length', y = 'rating', 
          col = 'genre', alpha = 0.6,
          shape = 'mpaa', shapeScheme = 21,
          size = 'budget',
          output_shiny = F,
          labs = 'title',
          main = 'size') %>% 
  layout(yaxis = list(zeroline = F))

4.4 轴标题

代码语言:javascript
复制
  dat[1:100,] %>% 
  easylabel(
          x = 'length', y = 'rating', 
          col = 'genre', alpha = 0.6,
          shape = 'mpaa', shapeScheme = 21,
          size = 'budget',
          output_shiny = F,
          labs = 'title',
          main = 'axis title',
          xlab = 'lenght minutes',
          ylab = 'rating score',
          showgrid = T) %>% 
  layout(yaxis = list(zeroline = F))

5火山图

5.1 用到的数据

这里我们需要用到easyVolcano()函数, 输入文件为DESeq2, limmaEdgeR计算的差异基因结果。😂 这里我准备另一个我之前计算的limma结果。🥰

代码语言:javascript
复制
all_diff <- read.csv("./alldiff_paired.csv",row.names = 1)
DT::datatable(all_diff)

5.2 初步绘图

easyVolcano会使用自动识别DESeq2, limmaEdgeR计算的差异基因结果, 但默认是使用FDR。🫠

代码语言:javascript
复制
easyVolcano(all_diff,useQ = T,
            output_shiny = F,
            startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05])

5.3 调整输入数据

手动选择x, y轴。😏

代码语言:javascript
复制
easyVolcano(all_diff, 
            useQ = F,
            x = 'logFC',
            y = 'P.Value',
            startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05],
            output_shiny = F)

5.4 MA plot

需要用到easyMAplot函数, 也是非常容易上手.😗

代码语言:javascript
复制
easyMAplot(all_diff, useQ = T,
           startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05],
           output_shiny = F)

5.5 展示基因全名

有时候我们不光想展示Gene Symbol, 还想展示它的全名, 但是手动检索会非常麻烦, easyVolcano可以完美地帮你解决这个问题.🤩

代码语言:javascript
复制
easyVolcano(all_diff, useQ = T, 
            fullGeneNames = T,
            output_shiny = F
            )

5.6 左右底角添加小标题

代码语言:javascript
复制
library(RColorBrewer)

colScheme <- c('darkgrey', brewer.pal(9, 'RdYlBu')[c(9:7, 3:1)])

easyVolcano(all_diff,
            useQ = F, fullGeneNames = T,
            Ltitle = expression(symbol("\254") ~ "Left"),
            Rtitle = expression("Right" ~ symbol("\256")),
            LRtitle_side = 1, # LRtitle_side = 1 bottom ; LRtitle_side = 3 top;
            cex.lab = 0.9, cex.axis = 0.8,
            fccut = c(1, 2), fdrcutoff = 0.2,
            ylim = c(0, 6), xlim = c(-5, 5),
            colScheme = colScheme,
            startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05],
            output_shiny = F
            )

5.7 控制label方向

我们在这里示范一下水平方向垂直方向.

代码语言:javascript
复制
p_horiz <- easyVolcano(all_diff,
            useQ = F, fullGeneNames = T,
            Ltitle = expression(symbol("\254") ~ "Left"),
            Rtitle = expression("Right" ~ symbol("\256")),
            LRtitle_side = 1, # LRtitle_side = 1 bottom ; LRtitle_side = 3 top;
            cex.lab = 0.9, cex.axis = 0.8,
            fccut = c(1, 2), fdrcutoff = 0.2,
            ylim = c(0, 6), xlim = c(-5, 5),
            colScheme = colScheme,
            labelDir = "horiz",
            startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05],
            output_shiny = F
            )

p_vert <- easyVolcano(all_diff,
            useQ = F, fullGeneNames = T,
            Ltitle = expression(symbol("\254") ~ "Left"),
            Rtitle = expression("Right" ~ symbol("\256")),
            LRtitle_side = 1, # LRtitle_side = 1 bottom ; LRtitle_side = 3 top;
            cex.lab = 0.9, cex.axis = 0.8,
            fccut = c(1, 2), fdrcutoff = 0.2,
            ylim = c(0, 6), xlim = c(-5, 5),
            colScheme = colScheme,
            labelDir = "vert",
            startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05],
            output_shiny = F
            )


plotly::subplot(p_horiz, p_vert, nrows = 2, shareY = T, titleX = T, margin = 0.05)

5.8 统一label和point的颜色

我们经常会遇到这种问题, 希望labelpoint统一颜色, 这样会更加美观。🤒 这也提供了相应的解决办法, 设置text_col = "match"以及 line_col = "match"即可.🥳

代码语言:javascript
复制
easyVolcano(all_diff,
            useQ = F, fullGeneNames = T,
            Ltitle = expression(symbol("\254") ~ "Left"),
            Rtitle = expression("Right" ~ symbol("\256")),
            LRtitle_side = 1, # LRtitle_side = 1 bottom ; LRtitle_side = 3 top;
            cex.lab = 0.9, cex.axis = 0.8,
            fccut = c(1, 2), fdrcutoff = 0.2,
            ylim = c(0, 6), xlim = c(-5, 5),
            colScheme = colScheme,
            startLabels = rownames(all_diff)[all_diff$P.Value < 0.01],
            line_col = "match", text_col = "match",
            rectangles = T, border_col = NA,
            rect_col = "match", border_radius = 20, padding = 5,
            output_shiny = F
            )

6曼哈顿图

这里我们也让pointlabel的颜色统一起来吧,颜值提升一下。😘

代码语言:javascript
复制
library(CMplot)

data("cattle50K")

chromCols <- RColorBrewer::brewer.pal(6, 'Paired')

easyManhattan(cattle50K, 
              chrom = "chr",
              pos = "pos", 
              p = "Somatic cell score", 
              chromCols = chromCols,
              ylab = "Somatic cell score",
              output_shiny = F,
              labs = "SNP",
              npeaks = 10, ## 标注peak前10
              labelDir = "vert",
              line_col = "match", text_col = "match",
              rectangles = T, border_col = NA,
              rect_col = "match", border_radius = 20, padding = 5,
              )

最后祝大家早日不卷!~


本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-12-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 生信漫卷 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1写在前面
  • 2用到的包
  • 3散点图
    • 3.1 初步绘图
      • 3.2 简单导出文件
        • 3.3 导出为ploty对象
        • 4美化细节
          • 4.1 colour
            • 4.2 shape
              • 4.3 size
                • 4.4 轴标题
                • 5火山图
                  • 5.1 用到的数据
                    • 5.2 初步绘图
                      • 5.3 调整输入数据
                        • 5.4 MA plot
                          • 5.5 展示基因全名
                            • 5.6 左右底角添加小标题
                              • 5.7 控制label方向
                                • 5.8 统一label和point的颜色
                                • 6曼哈顿图
                                领券
                                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档