写在前面
我们在画图的时候经常需要标记某个值, 如散点图
中的某个具体的点, 火山图
中的某个基因
, 但对于代码不太熟悉的小白来说, 还是有一定难度的.🤪
本期和大家介绍一个基于shiny
轻松进行label
的包, 即easylabel
包, 轻松实现交互式label
, 麻麻再也不用担心你的画图标记啦.😗
用到的包
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.1 初步绘图
我们先简单画个散点图, 试着标记一下吧。
这里是可以交互的,大家直接点一下就标记了哦。🤩
dat <- movies_long
dat %>%
easylabel(x = 'length',
y = 'rating',
labs = 'title',
colScheme = 'royalblue')
![](https://img.haomeiwen.com/i24475539/4f9a9e2c4a151f66.png)
3.2 简单导出文件
接着在底部可以找到输出按钮,点击后导出你需要的格式吧~😏
![](https://img.haomeiwen.com/i24475539/f7d2b7aa84c3c83f.png)
3.3 导出为ploty对象
我们也可以通过设置output_shiny = F
, 不激活shiny
而直接导出为ploty
对象, 依然是可交互的哦, 请随意移动。🤓
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)
![](https://img.haomeiwen.com/i24475539/8adfe7cf7ec7db93.png)
美化细节
接着我们做一些细节的美化, 支持colour
, shape
, size
等设置。😉
4.1 colour
easylabel(dat,
x = 'length', y = 'budget',
col = 'genre', alpha = 0.6,
output_shiny = F,
labs = 'title',
main = 'colour')%>%
layout(yaxis = list(zeroline = F))
![](https://img.haomeiwen.com/i24475539/7f922bb843dae13b.png)
4.2 shape
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))
![](https://img.haomeiwen.com/i24475539/d2f02494848ed0e9.png)
4.3 size
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))
![](https://img.haomeiwen.com/i24475539/799eb1a434e52dfb.png)
4.4 轴标题
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))
![](https://img.haomeiwen.com/i24475539/7d71e86a9d9602ff.png)
火山图
5.1 用到的数据
这里我们需要用到easyVolcano()
函数, 输入文件为DESeq2
, limma
或EdgeR
计算的差异基因
结果。😂
这里我准备另一个我之前计算的limma
结果。🥰
all_diff <- read.csv("./alldiff_paired.csv",row.names = 1)
DT::datatable(all_diff)
![](https://img.haomeiwen.com/i24475539/cb59656fd0b3a6dc.png)
5.2 初步绘图
easyVolcano
会使用自动识别DESeq2
, limma
或EdgeR
计算的差异基因
结果, 但默认是使用FDR
。🫠
easyVolcano(all_diff,useQ = T,
output_shiny = F,
startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05])
![](https://img.haomeiwen.com/i24475539/5dd7f4da40467a18.png)
5.3 调整输入数据
手动选择x
, y
轴。😏
easyVolcano(all_diff,
useQ = F,
x = 'logFC',
y = 'P.Value',
startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05],
output_shiny = F)
![](https://img.haomeiwen.com/i24475539/f6de5b1437af5844.png)
5.4 MA plot
需要用到easyMAplot
函数, 也是非常容易上手.😗
easyMAplot(all_diff, useQ = T,
startLabels = rownames(all_diff)[all_diff$adj.P.Val < 0.05],
output_shiny = F)
![](https://img.haomeiwen.com/i24475539/f29a9fd1048d7ef4.png)
5.5 展示基因全名
有时候我们不光想展示Gene Symbol
, 还想展示它的全名, 但是手动检索会非常麻烦, easyVolcano
可以完美地帮你解决这个问题.🤩
easyVolcano(all_diff, useQ = T,
fullGeneNames = T,
output_shiny = F
)
![](https://img.haomeiwen.com/i24475539/75a81ecfc942e28a.png)
5.6 左右底角添加小标题
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
)
![](https://img.haomeiwen.com/i24475539/a257f8f40be1761b.png)
5.7 控制label方向
我们在这里示范一下水平方向和垂直方向.
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)
![](https://img.haomeiwen.com/i24475539/7f99e04bb5a99c4c.png)
5.8 统一label和point的颜色
我们经常会遇到这种问题, 希望label
和point
统一颜色, 这样会更加美观。 🤒
这也提供了相应的解决办法, 设置text_col = "match"
以及 line_col = "match"
即可.🥳
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
)
![](https://img.haomeiwen.com/i24475539/5a579d76116573bd.png)
曼哈顿图
这里我们也让point
和label
的颜色统一起来吧,颜值提升一下。😘
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,
)
![](https://img.haomeiwen.com/i24475539/72f8a2fb6588bd8f.png)
<img src="https://img.haomeiwen.com/i24475539/c7527a8a4f8e4ec4.png" alt="刨冰" style="zoom:25%;" />
<center>最后祝大家早日不卷!~</center>
点个在看吧各位~ ✐.ɴɪᴄᴇ ᴅᴀʏ 〰
<center> <b>📍 往期精彩 <b> </center>
📍 <font size=1>🤩 ComplexHeatmap | 颜狗写的高颜值热图代码!</font>
📍 <font size=1>🤥 ComplexHeatmap | 你的热图注释还挤在一起看不清吗!?</font>
📍 <font size=1>🤨 Google | 谷歌翻译崩了我们怎么办!?(附完美解决方案)</font>
📍 <font size=1>🤩 scRNA-seq | 吐血整理的单细胞入门教程</font>
📍 <font size=1>🤣 NetworkD3 | 让我们一起画个动态的桑基图吧~</font>
📍 <font size=1>🤩 RColorBrewer | 再多的配色也能轻松搞定!~</font>
📍 <font size=1>🧐 rms | 批量完成你的线性回归</font>
📍 <font size=1>🤩 CMplot | 完美复刻Nature上的曼哈顿图</font>
📍 <font size=1>🤠 Network | 高颜值动态网络可视化工具</font>
📍 <font size=1>🤗 boxjitter | 完美复刻Nature上的高颜值统计图</font>
📍 <font size=1>🤫 linkET | 完美解决ggcor安装失败方案(附教程)</font>
📍 <font size=1>......</font>
本文由mdnice多平台发布
网友评论