十一假期飞快的过去了,小伙伴们都度过了一个难忘的假期了吧?是不是感觉十一美美的不想上班学习呢?不管假期如何,工作/学习还是要继续的。今天小编就带给大家一个美美的棒棒糖图,让你的科研结果也能美美的展示!
这是一个R包,名字叫做“G3viz”,是一个专门绘制基因突变的棒棒糖图的。先来看一下颜值,你觉得OK呢再接着往下看。
是不是很OK?
怎么样才能画出这么高颜值的棒棒糖图呢?小编这就进入正题。
第一,安装
方法一:从CRAN库直接安装
install.packages("g3viz", repos = "http://cran.us.r-project.org")
方法二:从Github开发版安装
#检查R包devtools是否安装
if("devtools" %in% rownames(installed.packages()) == FALSE){
install.packages("devtools")
}
# install from github
devtools::install_github("g3viz/g3viz")
第二,调用“G3viz”
#注意此时字母均为小写
library("g3viz")
第三,绘图
G3viz包接受三种类型的绘图文件,分别为MAF文件、CSV/TSV文件以及cbioportal数据库文件。
(1)MAF文件绘图
MAF文件格式详见链接:https://docs.gdc.cancer.gov/Data/File_Formats/MAF_Format/
绘图代码
# System file
maf.file <- system.file("extdata", "TCGA.BRCA.varscan.somatic.maf.gz", package = "g3viz")
mutation.dat <- readMAF(maf.file)chart.options <- g3Lollipop.theme(theme.name = "default",
title.text = "PIK3CA gene (default theme)")
g3Lollipop(mutation.dat,
gene.symbol = "PIK3CA",
plot.options = chart.options,
output.filename = "default_theme")
绘图结果如下:
(2)CSV或TSV文件绘图
CSV表头如下:
Hugo_Symbol,Chromosome,Start_Position,End_Position,Strand,Variant_Classification,Variant_Type,Reference_Allele,Tumor_Seq_Allele1,Tumor_Seq_Allele2,amino_acid_change
绘图代码
# load data
mutation.csv <- system.file("extdata", "ccle.csv", package = "g3viz")
mutation.dat <- readMAF(mutation.csv,
gene.symbol.col = "Hugo_Symbol",
variant.class.col = "Variant_Classification",
protein.change.col = "amino_acid_change",
sep = ",") # column-separator of csv file
g3Lollipop(mutation.dat,
gene.symbol = "TP53",
protein.change.col = "amino_acid_change",
btn.style = "blue", # blue-style chart download buttons
output.filename = "customized_plot")
绘图结果如下:
(3)cBioPortal库文件绘图
绘图代码
# Retrieve mutation data of "msk_impact_2017" from cBioPortal
mutation.dat <- getMutationsFromCbioportal("msk_impact_2017", "TP53")
# "cbioportal" chart theme
plot.options <- g3Lollipop.theme(theme.name = "cbioportal",
title.text = "TP53 gene (cbioportal theme)",
y.axis.label = "# of TP53 Mutations")
g3Lollipop(mutation.dat,
gene.symbol = "TP53",
btn.style = "gray", # gray-style chart download buttons
plot.options = plot.options,
output.filename = "cbioportal_theme")
绘图结果如下:
如果想查看cBioPortal库有哪些文件呢?安装R包“cgdsr”就可以了。
安装命令
install_github("cBioPortal/cgdsr")
加载R包并查看
library(cgdsr)
cgds <- CGDS("http://www.cbioportal.org/")
# To list all studies
all.studies <- cgdsr::getCancerStudies(cgds)
# Pick up a cancer study with mutation data
mutation.dat <- g3viz::getMutationsFromCbioportal("all_stjude_2016", "TP53")
这个R包还是可以进行定制化绘图的,通过对plot.options进行设置,具体如下:
# set up chart options
plot.options <- g3Lollipop.options(
# Chart settings
chart.width = 600,
chart.type = "pie",
chart.margin = list(left = 30, right = 20, top = 20, bottom = 30),
chart.background = "#d3d3d3",
transition.time = 300,
# Lollipop track settings
lollipop.track.height = 200,
lollipop.track.background = "#d3d3d3",
lollipop.pop.min.size = 1,
lollipop.pop.max.size = 8,
lollipop.pop.info.limit = 5.5,
lollipop.pop.info.dy = "0.24em",
lollipop.pop.info.color = "white",
lollipop.line.color = "#a9A9A9",
lollipop.line.width = 3,
lollipop.circle.color = "#ffdead",
lollipop.circle.width = 0.4,
lollipop.label.ratio = 2,
lollipop.label.min.font.size = 12,
lollipop.color.scheme = "dark2",
highlight.text.angle = 60,
# Domain annotation track settings
anno.height = 16,
anno.margin = list(top = 0, bottom = 0),
anno.background = "#d3d3d3",
anno.bar.fill = "#a9a9a9",
anno.bar.margin = list(top = 4, bottom = 4),
domain.color.scheme = "pie5",
domain.margin = list(top = 2, bottom = 2),
domain.text.color = "white",
domain.text.font = "italic 8px Serif",
# Y-axis label
y.axis.label = "# of TP53 gene mutations",
axis.label.color = "#303030",
axis.label.alignment = "end",
axis.label.font = "italic 12px Serif",
axis.label.dy = "-1.5em",
y.axis.line.color = "#303030",
y.axis.line.width = 0.5,
y.axis.line.style = "line",
y.max.range.ratio = 1.1,
# Chart title settings
title.color = "#303030",
title.text = "TP53 gene (customized chart options)",
title.font = "bold 12px monospace",
title.alignment = "start",
# Chart legend settings
legend = TRUE,
legend.margin = list(left=20, right = 0, top = 10, bottom = 5),
legend.interactive = TRUE,
legend.title = "Variant classification",
# Brush selection tool
brush = TRUE,
brush.selection.background = "#F8F8FF",
brush.selection.opacity = 0.3,
brush.border.color = "#a9a9a9",
brush.border.width = 1,
brush.handler.color = "#303030",
# tooltip and zoom
tooltip = TRUE,
zoom = TRUE
)
参数释义:
OptionDescription
Chart settings
chart.width chart width in px. Default 800.
chart.type pop type, pie or circle. Default pie.
chart.margin specify chart margin in list format. Default list(left = 40, right = 20, top = 15, bottom = 25).
chart.background chart background. Default transparent.
transition.time chart animation transition time in millisecond. Default 600.
Lollipop track settings
lollipop.track.height height of lollipop track. Default 420.
lollipop.track.background background of lollipop track. Default rgb(244,244,244).
lollipop.pop.min.size lollipop pop minimal size in px. Default 2.
lollipop.pop.max.size lollipop pop maximal size in px. Default 12.
lollipop.pop.info.limit threshold of lollipop pop size to show count information in middle of pop. Default 8.
lollipop.pop.info.color lollipop pop information text color. Default #EEE.
lollipop.pop.info.dy y-axis direction text adjustment of lollipop pop information. Default -0.35em.
lollipop.line.color lollipop line color. Default rgb(42,42,42).
lollipop.line.width lollipop line width. Default 0.5.
lollipop.circle.color lollipop circle border color. Default wheat.
lollipop.circle.width lollipop circle border width. Default 0.5.
lollipop.label.ratio lollipop click-out label font size to circle size ratio. Default 1.4.
lollipop.label.min.font.size lollipop click-out label minimal font size. Default 10.
lollipop.color.scheme color scheme to fill lollipop pops. Default accent. Check color schemes for details.
highlight.text.angle the rotation angle of on-click highlight text in degree. Default 90.
Domain annotation track settings
anno.height height of protein structure annotation track. Default 30.
anno.margin margin of protein structure annotation track. Default list(top = 4, bottom = 0).
anno.background background of protein structure annotation track. Default transparent.
anno.bar.fill background of protein bar in protein structure annotation track. Default #E5E3E1.
anno.bar.margin margin of protein bar in protein structure annotation track. Default list(top = 2, bottom = 2).
domain.color.scheme color scheme of protein domains. Default category10. Check color schemes for details.
domain.margin margin of protein domains. Default list(top = 0, bottom = 0).
domain.text.font domain label text font in shorthand format. Default normal 11px Arial.
domain.text.color domain label text color. Default #F2F2F2.
Y-axis settings
y.axis.label Y-axis label text. Default # of mutations.
axis.label.font css font style shorthand (font-style font-variant font-weight font-size/line-height font-family). Default normal 12px Arial.
axis.label.color axis label text color. Default #4f4f4f.
axis.label.alignment axis label text alignment (start/end/middle). Default middle
axis.label.dy text adjustment of axis label text. Default -2em.
y.axis.line.color color of y-axis in-chart lines (ticks). Default #c4c8ca.
y.axis.line.style style of y-axis in-chart lines (ticks), dash or line. Default dash.
y.axis.line.width width of y-axis in-chart lines (ticks). Default 1.
y.max.range.ratio ratio of y-axis range to data value range. Default 1.1.
Chart title settings
title.text title of chart. Default "".
title.font font of chart title. Default normal 16px Arial.
title.color color of chart title. Default #424242.
title.alignment text alignment of chart title (start/middle/end). Default middle.
title.dy text adjustment of chart title. Default 0.35em.
Chart legend settings
legend if show legend. Default TRUE.
legend.margin legend margin in list format. Default list(left = 10, right = 0, top = 5, bottom = 5).
legend.interactive legend interactive mode. Default TRUE.
legend.title legend title. If NA, use factor name as factor.col. Default is NA.
Brush selection tool settings
brush if show brush. Default TRUE.
brush.selection.background background color of selection brush. Default #666.
brush.selection.opacity background opacity of selection brush. Default 0.2.
brush.border.color border color of selection brush. Default #969696.
brush.handler.color color of left and right handlers of selection brush. Default #333.
brush.border.width border width of selection brush. Default 1.
Tooltip and zoom tools
tooltip if show tooltip. Default TRUE.
zoom if enable zoom feature. Default TRUE.
此R包简单有简单的用法,几句代码就能轻松画出发表的图,同时设置可调整的参数让你对其进行个性化设置,可以说是很友好的一个R包了,小伙伴们快快用起来吧!