qplot(ggbio)
qplot()所属R语言包:ggbio
Generic qplot function
通用qplot功能
译者:生物统计家园网 机器人LoveR
描述----------Description----------
To visualize different objects describing biological data, we develop this generic function, and developed new types of geoms to each one. Try to make simple API and following the grammar of graphics, use higher level graphic package like ggplot2 to produce high quality graphics.
可视化描述生物数据的不同对象,我们开发这种通用的功能,每一个开发新类型的geoms。尽量让简单的API和图形的语法,使用像ggplot2更高级别的图形软件包,以生产高品质的图形。
用法----------Usage----------
## For object data.frame
## S4 method for signature 'data.frame'
qplot(data, ...)
## For object matrix
## S4 method for signature 'matrix'
qplot(data, ...)
## For object numeric
## S4 method for signature 'numeric'
qplot(data, ...)
## For object numeric
## S4 method for signature 'integer'
qplot(data, ...)
## For object GRanges
## S4 method for signature 'GRanges'
qplot(data, x, y,...,
facet_gr, legend = TRUE,
show.coverage = TRUE,
show.gaps = FALSE,
show.label = FALSE,
geom = c("full", "line","point",
"segment",
"coverage.line", "coverage.polygon"))
## For object GRangesList
## S4 method for signature 'GRangesList'
qplot(data, ..., freq, show.label = FALSE,
show.gaps = TRUE, scale.size = c(5, 17),
label.type = c("name", "count"),
label.size = 5, label.color = "black")
## For object IRanges
## S4 method for signature 'IRanges'
qplot(data, ..., legend = TRUE,
geom = c("full", "segment",
"coverage.line", "coverage.polygon"))
## For object GappedAlignments
## S4 method for signature 'GappedAlignments'
qplot(data, ..., which,
geom = c("gapped.pair", "full"),
show.junction = FALSE)
## For object BamFile
## S4 method for signature 'BamFile'
qplot(data, ..., which,
bsgenome, resize.extra = 10, show.coverage = TRUE,
geom = c("gapped.pair", "full",
"coverage.line",
"coverage.polygon", "mismatch.summary"))
## For object character
## S4 method for signature 'character'
qplot(data, ..., which,
bsgenome, resize.extra = 10, show.coverage = TRUE,
geom = c("gapped.pair", "full",
"coverage.line", "coverage.polygon",
"mismatch.summary"))
## For object TranscriptDb
## S4 method for signature 'TranscriptDb'
qplot(data, which, ...,
geom = c("full", "single", "tx"))
## For object BSgenome
## S4 method for signature 'BSgenome'
qplot(data, name, ...,
geom = c("text", "segment", "point", "rectangle"))
## For object Rle
## S4 method for signature 'Rle'
qplot(data, lower, ...,
size, shape, color, alpha,
xlab = "x", ylab = "y",
geom = c("point", "line", "segment"),
type = c("raw", "viewMaxs","viewMins",
"viewSums", "viewMeans"))
## For object RleList
## S4 method for signature 'RleList'
qplot(data, lower, ...,
size, shape, color, alpha,
facetByRow = TRUE,
xlab = "x", ylab = "y",
geom = c("point", "line", "segment"),
type = c("raw", "viewMaxs","viewMins",
"viewSums", "viewMeans"))
参数----------Arguments----------
参数:data
A data.frame, matrix, GRanges, BSgenome, TranscriptDb, GappedAlignments object or any other objects for which the qplot method is defined.
一个data.frame,matrix,GRanges,BSgenome,TranscriptDb,GappedAlignments对象或为,其中qplot方法定义的任何其他对象。
参数:x
x value, start/end/midpoint without quotes. e.g x = start, default use the midpoint.
x的值,开始/结束/不带引号的中点。 e.gx = start,默认使用midpoint。
参数:y
y value, only be used in geom: point/line. Should be a single name of the column names in the elementMetatata without quotes. e.g y = score
y的值,只可用于在GEOM:点/线。应该是一个单一的名称在不含引号elementMetatata的列名。 e.gy = score
参数:geom
Geom to use (Single character for now). Please see section Geometry for details.
GEOM使用(现在的单个字符)。详情请参阅节几何。
参数:facet_gr
A GRanges object which contains the regions you want to facet on.
一个GRanges对象,其中包含您要面对的区域。
参数:size
Size for point or lines. Could equal a column name or a fixed number. When it's fixed, please use I() to wrap the value.
为点或线的大小。就相当于列名或一个固定的数字。当它固定的,请使用I()包装的价值。
参数:shape
Shape for point or lines. Could equal a column name or a fixed number. When it's fixed, please use I() to wrap the value.
点或线的形状。就相当于列名或一个固定的数字。当它固定的,请使用I()包装的价值。
参数:color
Color for point for lines. Could equal a column name or a fixed character. When it's fixed, please use I() to wrap the value.
颜色为线的点。就相当于列名或一个固定的字符。当它固定的,请使用I()包装的价值。
参数:alpha
Alpha blending. Could equal a column name or a fixed number. When it's fixed, please use I() to wrap the value.
Alpha混合。就相当于列名或一个固定的数字。当它固定的,请使用I()包装的价值。
参数:lower
When object is Rle/RleList, and use other types of methods which is not "raw", at least a lower parameters which passed to slice function is required.
当对象是RLE / RleList,与使用其他类型的方法,这是不是“原始”,需要至少一个较低的参数传递slice函数。
参数:name
Passed to getSeq in BSgenome package. A character vector containing the names of the sequences in 'x' where to get the subsequences from, or a GRanges object, or a RangedData object, or a named RangesList object, or a named Ranges object. The RangesList or Ranges object must be named according to the sequences in 'x' where to get the subsequences from. If 'names' is missing, then 'seqnames(x)' is used.
传给getSeqBSgenome包。一个特征向量包含X从哪里得到的子序列从或农庄对象的,或RangedData对象,或一个名为RangesList对象,或已命名的范围对象的序列的名称。必须命名为X从哪里得到的子序列从序列RangesList或范围对象。如果名失踪,然后seqnames(X)使用。
参数:legend
A logical value indicates whether to show legend or not. Default is TRUE
一个逻辑值,指明是否显示图例与否。默认是TRUE
参数:which
A GRanges object to subset the result, usually passed to the ScanBamParam function.
一个GRanges对象子集的结果,通常是通过ScanBamParam功能。
参数:show.junction
A logical value indicates whether to show the line between junction reads or not.
一个逻辑值,表明是否显示行之间的交界处读取或没有。
参数:show.coverage
A logical value indicates whether to show coverage or not. This is used for geom "mismatch.summary".
一个逻辑值,指明是否显示覆盖或没有。这是用于GEOM“mismatch.summary”。
参数:show.gaps
A logical value indicates whether to show gaps or not. This is used for geom "full".
一个逻辑值,指示是否显示空白或。这是用于GEOM“全”。
参数:show.label
A logical value indicates whether to show labels or not. This is used for geom "full".
一个逻辑值,指明是否显示标签。这是用于GEOM“全”。
参数:freq
A numeric vector indicating counts. This used for GRangesList plot when you try to produce a summary for gene model or alternative splicing, the name of the vector corresponding to the names of the GRangesList.
一个数值向量显示计数。这GRangesList图的,当您尝试产生基因模型或剪接,向量的名称对应GRangesList名摘要。
参数:resize.extra
A numeric value used to add buffer to intervals to compute stepping levels on.
添加缓冲间隔计算加强各级的数值。
参数:bsgenome
A BSgenome object. Only need for geom "mismatch.summary".
BSgenome对象。只需要GEOM“mismatch.summary”。
参数:xlab
x label.
X标签。
参数:ylab
y label.
Ÿ标签。
参数:facetByRow
A logical value, default is TRUE ,facet RleList by row. If FALSE, facet by column.
一个逻辑值,默认为TRUE,面行RleList。如果为FALSE,面列。
参数:type
For Rle/RleList, "raw" plot everything, so be careful, that would be pretty slow if you have too much data. For "viewMins", "viewMaxs", "viewMeans", "viewSums", require extra arguments to slice the object. so users need to at least provide lower, more details and control please refer the the manual of slice function in IRanges. For "viewMins", "viewMaxs", we use viewWhichMin and viewWhichMax to get x scale, for "viewMeans", "viewSums", we use window midpoint as x.
为RLE / RleList,“原始”的图的一切,所以一定要小心,那将是非常缓慢的,如果你有太多的数据。对于“viewMins”,“viewMaxs”,的“viewMeans”,“viewSums”,需要额外的参数,以切片的对象。因此,用户需要提供至少lower的更多细节和控制,请参阅slice在IRanges函数手册。为“viewMins”,“viewMaxs”,我们使用viewWhichMin和viewWhichMaxX比例,为“viewMeans”,“viewSums”,我们使用为x窗口中点。
参数:scale.size
A numeric vector of length two specifying the size of point from minimum to maximum.
指定一个长度为2的数字矢量点的大小,从最小到最大。
参数:label.type
Either "name" or "count". "name" try to use the name of list to label the model, but "count" use information from freq to label it.
无论是“名”或“计数”。尝试使用“名称”列表标签的模型的名称,但“伯爵”从频率使用信息标签。
参数:label.size
Size of label.
标签的大小。
参数:label.color
Color of label.
标签的颜色。
参数:...
Extra parameters. Usually are those parameters used in qplot to control aesthetics or geometries.
额外的参数。通常是在qplot这些参数用来控制美学或几何。
值----------Value----------
A ggplot object, so you can use common features from ggplot2 package to manipulate the plot.
一个ggplot对象,所以你可以使用共同的特点,从ggplot2包操纵的图。
介绍----------Introduction----------
qplot is redefined as generic s4 method inside this package, user could use qplot in the way they are familiar with, and we are also setting limitation inside this package, like
qplot这个包内S4作为通用方法重新定义,用户可以使用qplot的方式,他们所熟悉的,我们也在这里面包的限制,如
scales X scales is always genomic coordinates in most cases, x could be specified as start/end/midpoint when it's special geoms for interval data like point/line
X秤秤是始终在大多数情况下,基因组坐标,x可以被指定为开始/结束/中点时,它的像点/线间隔数据geoms
colors Try to use default color scheme defined in biovizBase package as possible as it can
颜色尝试使用尽可能biovizBase包中定义的默认配色方案,因为它可以
几何----------Geometry----------
We have developed new geom for different objects, some of them may require extra parameters you need to provide. Some of the geom are more like geom + stat in ggplot2 package. e.g. "coverage.line" and "coverage.polygon".We simply combine them together, but in the future, we plan to make it more general.
我们已经开发出新的针对不同的对象geom,其中一些人可能会要求您需要提供额外的参数。一些GEOM如GEOM + STAT ggplot2包。例如“coverage.line”和“coverage.polygon。”我们只是将它们合并在一起,但在未来,我们计划,使其更一般。
This package is designed for only biological data, especially genomic data if users want to explore the data in a more flexible way, you could simply coerce the GRanges to a data.frame, then just use formal qplot function in ggplot2, or qplot generic for data.frame.
这个包唯一的生物数据,尤其是基因组数据的设计,如果用户希望在一个更灵活的方式,探索数据,你可以简单地强迫GRanges数据框,然后就正式使用qplot功能ggplot2,或qplotdata.frame通用。
Some objects share the same geom so we introduce all the geom together in this section
一些对象共享相同的geom,所以我们在本节引入所有的GEOM
Showing all the intervals as stepped rectangle, colored by strand automatically.
阶梯式矩形自动链着色,显示所有的时间间隔。
For TranscripDb object, showing full model.
TranscripDb对象,呈现出完整的模型。
Showing all the intervals as stepped segments, colored by strand automatically.
阶梯段,链颜色自动显示所有的时间间隔。
For object BSgenome, show nucleotides as colored segment.
对象BSgenome,显示色段核苷酸。
For Rle/RleList, show histogram-like segments.
对于RLE / RleList,显示段直方图样。
Showing interval as line, the interval data could also be just single position when start = end, x is one of start/end/midpoint, y value is unquoted name in elementMetadata column names. y value is required.
的时间间隔的数据显示间隔为线,也只是单一的位置开始=结束时,x是一个开始/结束/中点,y的值是加引号在elementMetadata列名的名称。 y的值是必需的。
Showing interval as point, the interval data could also be just single position when start = end, x is one of start/end/midpoint, y value is unquoted name in elementMetadata column names. y value is required.
间隔的数据显示为点的时间间隔,也可以只是单一的位置开始=结束时,x是一个开始/结束/中点,y的值是加引号在elementMetadata列名的名称。 y的值是必需的。
For object BSgenome, show nucleotides as colored point.
对象BSgenome的,显示彩色点核苷酸。
Coverage showing as lines for interval data.
覆盖显示间隔数据线。
Coverage showing as polygon for interval data.
区间数据的多边形覆盖显示。
Splicing summary. The size and width of the line and rectangle should represent the counts in each model. Need to provide model.
拼接总结。线和矩形的大小和宽度应在每个模型代表计数。需要提供模型。
For TranscripDb object, showing single(reduced) model only.
TranscripDb对象,只显示单(减少)模型。
For TranscripDb object, showing transcirpts isoforms.
TranscripDb对象,显示transcirpts亚型。
Show GappedAlignments as special stepping plots, it make sure all the reads of the same pair or qname shown in the same level and nothing falls in between. Then you can use show.junction arguments show the junction as lines between junction reads if any.
显示GappedAlignments作为特别加强图,确保所有的读取相同的一对或在同一水平,并没有落在之间的QName。如果有的话,那么你可以使用show.junction参数显示之间的交界线交界处读取。
Showing color coded mismatched stacked bar to indicate the proportion of mismatching at each position, the reference is set to gray.
显示颜色编码匹配堆积条形图显示在每个位置上不匹配的比例,参考设置为灰色。
For object BSgenome, show nucleotides as colored text.
对象BSgenome,彩色文字显示核苷酸。
For object BSgenome, show nucleotides as colored rectangle.
对象BSgenome,显示彩色矩形核苷酸。
皱----------Faceting----------
Faceting in ggbio package is a little differnt from ggplot2 in several ways
皱ggbio包是从ggplot2几种方式有点不同的充
The faceted column could only be seqnames or regions on the genome. So we limited the formula passing to facet argument, e.g something \~ seqnames, is accepted formula, you can change "something" to variable name in the elementMetadata. But you can not change the second part.
面列只能是基因组seqnames或区域。因此,我们有限的传递方面参数的公式,例如一些\~seqnames的,被接受的公式,你可以改变的“东西”在elementMetadata的变量名。但你不能改变的第二部分。
Sometime, we need to view different regions, so we also have a facet_gr argument which accept a GRanges. If this is provided, it will override the default seqnames and use provided region to facet the graphics, this might be useful for different gene centric views.
有时,我们需要查看不同的区域,所以我们也有一个接受GRangesfacet_gr参数。如果这是规定,将覆盖默认seqnames,并提供区域使用面图形,这可能是有用的不同基因中心的意见。
作者(S)----------Author(s)----------
Tengfei Yin
举例----------Examples----------
## Not run: [#无法运行:]
library(ggbio)
## overide qplot[#overide qplot]
qplot(data = mtcars, mpg, cyl)
qplot(1:3)
qplot(volcano)
qplot(c(1, 2.2, 3.3))
ggplot2::qplot(1:3)
ggplot2::qplot(c(1, 2.2, 3.3))
ggplot2::qplot(volcano)
## GRanges[#农庄]
set.seed(1)
N <- 1000
library(GenomicRanges)
gr <- GRanges(seqnames =
sample(c("chr1", "chr2", "chr3"),
size = N, replace = TRUE),
IRanges(
start = sample(1:300, size = N, replace = TRUE),
width = sample(70:75, size = N,replace = TRUE)),
strand = sample(c("+", "-", "*"), size = N,
replace = TRUE),
value = rnorm(N, 10, 3), score = rnorm(N, 100, 30),
group = sample(c("Normal", "Tumor"),
size = N, replace = TRUE),
pair = sample(letters, size = N,
replace = TRUE))
qplot(gr)
qplot(gr, geom = "full")
qplot(gr, geom = "segment")
qplot(gr, geom = "line", y = value)
qplot(gr, geom = "point", y = value)
qplot(gr, geom = "coverage.line")
qplot(gr, geom = "coverage.polygon")
gr.sub <- gr[seqnames(gr) == "chr1"] #or [或]
p1 <- qplot(gr.sub, geom = "full") + opts(title = "full")
p2 <- qplot(gr.sub, geom = "point", y = value) + opts(title = "point")
p3 <- qplot(gr.sub, geom = "line", y = value) + opts(title = "line")
p4 <- qplot(gr.sub, geom = "coverage.line") + opts(title = "coverage.line")
p5 <- qplot(gr.sub, geom = "coverage.polygon") + opts(title = "coverage.polygon")
library(gridExtra)
grid.arrange(p1, p2, p3, p4, p5, ncol = 2)
qplot(gr, ncol = 2)
## faceting, use facets not facet[#小面,使用面不面]
qplot(gr, facets = group ~ seqnames)
qplot(gr, geom = "segment", facets = group ~ seqnames)
qplot(gr, geom = "line", y = value, facets = group ~ seqnames)
qplot(gr, geom = "point", y = value, facets = group ~ seqnames)
qplot(gr, geom = "coverage.line", facets = group ~ seqnames)
qplot(gr, geom = "coverage.polygon", facets = group ~ seqnames)
## facet gr[#侧面克的]
gr.region <- GRanges(c("chr1", "chr2", "chr3"),
IRanges(c(100, 200, 250),
width = 70))
## facet_grid[#facet_grid]
qplot(gr, facet_gr = gr.region)
## facet_wrap[#facet_wrap]
qplot(gr, facet_gr = gr.region, nrow = 2) +
scale_y_continuous(limits = c(0, 90))
## checvron[#checvron]
gr <- GRanges("chr1", IRanges(c(100, 200, 300), width = 50))
p <- qplot(gr)
gr.gaps <- gaps(gr)[-1]
values(gr.gaps)$score <- c(1, 100)
p1 <- p + geom_chevron(gr.gaps)
p2 <- p + geom_chevron(gr.gaps, aes(size = score), offset = "score",
chevron.height = c(0.1, 0.2))
p3 <- p + geom_chevron(gr.gaps, offset = -0.1)
tracks(p1, p2, p3)
## GRangesList[#GRangesList]
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
data(genesymbol)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
exons.tx <- exonsBy(txdb, by = "tx")
exons.rbm17 <- subsetByOverlaps(exons.tx, genesymbol["RBM17"])
nms <- names(exons.rbm17)
freqs <- c(100, 200, 300)
names(freqs) <- nms
p.splice1 <- qplot(exons.rbm17)
## when turning on frequency [#转弯时的频率]
p.splice <- qplot(exons.rbm17, freq = freqs, show.label = TRUE, label.type = "count",
scale.size = c(1, 5), label.size = 3)
p.splice2 <- qplot(exons.rbm17, freq = freqs, show.label = TRUE, offset = 0.05,
label.type = "count")
print(p.splice1)
print(p.splice2)
ir <- IRanges(c(10, 20, 30) ,width = 15)
qplot(ir)
ir <- ranges(gr[seqnames(gr) == "chr1"])[1:40]
p1 <- qplot(ir) + opts(title = "full")
p2 <- qplot(ir, geom = "segment")+ opts(title = "segment")
p3 <- qplot(ir, geom = "coverage.line")+ opts(title = "coverage.line")
p4 <- qplot(ir, geom = "coverage.polygon")+ opts(title = "coverage.polygon")
library(gridExtra)
grid.arrange(p1, p2, p3, p4, ncol = 2)
library(IRanges)
set.seed(1)
lambda <- c(rep(0.001, 4500), seq(0.001, 10, length = 500),
seq(10, 0.001, length = 500))
xVector <- rpois(1e4, lambda)
xRle <- Rle(xVector)
xRleList <- RleList(xRle, 2L * xRle)
qplot(xRle)
qplot(xRle, geom = "line")
qplot(xRle, geom = "segment")
qplot(xRle, type = "viewMaxs", lower = 5)
qplot(xRle, type = "viewMins", lower = 5)
qplot(xRle, type = "viewMeans", lower = 5)
qplot(xRle, type = "viewSums", lower = 5)
qplot(xRleList)
qplot(xRleList, geom = "segment")
qplot(xRleList, geom = "line")
qplot(xRleList, type = "viewMaxs", lower = 5)
qplot(xRleList, type = "viewMaxs", lower = 5, geom = "line")
qplot(xRleList, type = "viewSums", lower = 5, geom = "segment",
facetByRow = FALSE, color = I("red"), size = I(5))
qplot(xRle, size = y)
qplot(xRle, type = "viewSums", lower = 5)
qplot(xRle, type = "viewSums", lower = 5, size = I(10), color = I("red"),
alpha = y)
## End(Not run)[#结束(不运行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|