导语
GUIDE ╲
在R语言绘图中的一个常见问题是用大量点或标签标记散点图。
背景介绍
在我们的科研中,常常遇到需要用散点图、火山图或者曼哈顿图进行数据可视化,就会碰到一个问题,在众多的点中,哪些才是我们想要找到的呢?今天小编给大家介绍的这个R包easylabel,可以轻松标记散点图以及快速绘制火山图和 MA 图以进行基因表达分析。使用交互式shiny和绘图界面,我们可以将鼠标悬停在点上以查看特定点的位置,然后单击点以轻松标记它们。 还提供了一种直接导出为 PDF 以供发表的简单方法。
R包安装
代码语言:javascript复制install.packages("easylabel")
library(easylabel)
可视化介绍
01
散点图
使用 easylabel() 打开一个shiny的应用程序并绘制和标记散点图。
代码语言:javascript复制data(mtcars)
easylabel(mtcars, x = 'mpg', y = 'wt',
colScheme = 'royalblue')
调整颜色
代码语言:javascript复制easylabel(mtcars, x = 'mpg', y = 'wt',
col = 'cyl')
形状
代码语言:javascript复制# gapminder data set
if(!require(gapminder)) {install.packages("gapminder")}
library(gapminder)
easylabel(gapminder[gapminder$year == 2007, ], x = 'gdpPercap', y = 'lifeExp',
col = 'continent', shape = 'continent',
size = 10,
labs = 'country',
zeroline = FALSE)
大小设置
代码语言:javascript复制library(gapminder)
easylabel(gapminder[gapminder$year == 2007, ], x = 'gdpPercap', y = 'lifeExp',
col = 'continent', labs = 'country',
size = 'pop',
alpha = 0.6,
zeroline = FALSE)
坐标轴设置标题
代码语言:javascript复制easylabel(xymatrix, x = 'x', y = 'y', col = 'col',
colScheme = c('darkgrey', 'green3', 'gold3', 'blue'),
xlab = expression("log"[2] ~ " fold change post-Rituximab"),
ylab = expression("log"[2] ~ " fold change post-Tocilizumab"),
showgrid = TRUE)
02
火山图
示例数据
代码语言:javascript复制# Example DESeq2 object
head(volc1)
## baseMean log2FoldChange lfcSE stat pvalue
## 5_8S_rRNA 0.01625099 0.02726923 2.9811510 0.009147217 0.99270168
## 5S_rRNA 3.66321881 0.05989097 0.4115732 0.145517159 0.88430257
## 7SK 12.96667458 -0.46156215 1.3668722 -0.337677614 0.73560615
## A1BG 290.75694559 0.23486554 0.3514587 0.668259368 0.50396804
## A1BG-AS1 170.77906789 0.11800652 0.2001594 0.589562618 0.55548392
## A1CF 4.56855647 -1.23495475 0.4855212 -2.543565265 0.01097276
## padj
## 5_8S_rRNA NA
## 5S_rRNA 0.9823854
## 7SK 0.9528927
## A1BG 0.8956205
## A1BG-AS1 0.9117136
## A1CF 0.4531638
# Example limma object
head(volc2)
## logFC AveExpr t P.Value adj.P.Val B
## A1BG 0.7697662 6.389039 4.692064 0.0011239293 0.008610736 -1.16895727
## A1BG-AS1 0.5298897 3.610850 4.688657 0.0011293516 0.008638889 -0.85241114
## AAAS -0.4162720 5.349529 -5.578986 0.0003398373 0.004148831 0.17585449
## AACS -0.2049703 3.690271 -1.465073 0.1768461859 0.299064278 -5.88763988
## AAGAB 0.2970478 5.538436 5.446618 0.0004033869 0.004553688 -0.02478892
## AAK1 0.1969886 1.861988 1.286456 0.2302992497 0.362402197 -5.74356735
代码语言:javascript复制#MA plots
easyMAplot(volc2, useQ = TRUE)
配色方案
代码语言:javascript复制easyVolcano(volc2,
useQ = TRUE,
fccut = 0,
main = "Volcano title")
添加左右注释
代码语言:javascript复制easyVolcano(volc1,
useQ = TRUE, fullGeneNames = TRUE,
Ltitle = expression(symbol("254") ~ "Non-responder"),
Rtitle = expression("Responder" ~ symbol("256")),
LRtitle_side = 1,
cex.lab = 0.9, cex.axis = 0.8,
fccut = c(1, 2), fdrcutoff = 0.2,
ylim = c(0, 6), xlim = c(-5, 5),
colScheme = c('darkgrey', 'blue', 'orange', 'red'))
添加标签框
代码语言:javascript复制# Simple outlines
easyVolcano(volc2, useQ = TRUE, fccut = 0,
rectangles = TRUE)
# Red outlined labels, rounded ends
easyVolcano(volc2, useQ = TRUE, fullGeneNames = TRUE,
rectangles = TRUE,
padding = 5,
border_radius = 10,
line_col = 'red',
border_col = 'red',
text_col = 'red')
代码语言:javascript复制# Transparent grey rectangles, rounded ends
easyMAplot(volc2, fdrcut = c(0.05, 0.01, 0.001), size = 6, useQ = TRUE,
alpha = 0.75, outline_col = NA,
fullGeneNames = TRUE,
colScheme = c('darkgrey', brewer.pal(9, 'RdYlBu')[c(7:9, 3:1)]),
rectangles = TRUE,
border_col = NA,
padding = 5,
rect_col = adjustcolor('grey', alpha.f = 0.6),
border_radius = 20)
# White text on black background, no rounding
easyVolcano(volc2, useQ = TRUE, fullGeneNames = TRUE,
fccut = 0,
rectangles = TRUE,
padding = 4,
border_radius = 0,
rect_col = 'black',
text_col = 'white',
border_col = NA)
03
曼哈顿图
可以使用函数 easyManhattan() 标记曼哈顿图。
代码语言:javascript复制# https://www.ebi.ac.uk/gwas/studies/GCST003156
library(data.table)
SLE_gwas <- fread('../bentham_2015_26502338_sle_efo0002690_1_gwas.sumstats.tsv')
# Simple Manhattan plot
easyManhattan(SLE_gwas)
# 4 colours for chromosomes
easyManhattan(SLE_gwas, chromCols = RColorBrewer::brewer.pal(4, 'Paired'))
Locus plots
代码语言:javascript复制# Create a locus plot over one chromosomal region
library(plotly)
p1 = easyManhattan(SLE_gwas[SLE_gwas$chrom == 6 &
SLE_gwas$pos >= 28e6 &
SLE_gwas$pos <= 34e6, ],
output_shiny = FALSE, labs = "rsid",
startLabels=c("rs115466242", "rs2853999"),
npeaks = 3)
# To annotate genes in that region
source("https://raw.githubusercontent.com/KatrionaGoldmann/BioOutputs/master/R/bio_gene_locations.R")
library(ggbio)
library(gginnards)
library(ggrepel)
if (! "EnsDb.Hsapiens.v75" %in% rownames(installed.packages()))
BiocManager::install("EnsDb.Hsapiens.v75")
p2 = bio_gene_locations(6, c(28e6, 34e6),
subset_genes = c('HLA-F', 'HLA-G', 'HLA-A', 'HLA-E',
'HLA-C', 'HLA-B', 'HLA-DRA',
'HLA-DRB5', 'HLA-DRB1', 'HLA-DQA1',
'HLA-DQB1', 'HLA-DQA2', 'HLA-DQB2',
'HLA-DOB', 'HLA-DMB', 'HLA-DMA',
'HLA-DOA', 'HLA-DPA1', 'HLA-DPB1'))
plotly::subplot(p1, p2$plotly_location %>% layout(yaxis=list(range=c(0.25, 2))),
shareY = T, titleX = T, margin=0.05,
nrows=2, heights=c(0.7, 0.3))
小编总结
easylabel通过shiny的形式,可以自由的进行可视化调整,对于以上示例我们可以看到,easylabel的画图美观效果是很好的,基本不需要后期进行调整,大家可以自己动手尝试一下哦!