R: One-dimensional density/histogram plots for flow data
densityplot
R Documentation
One-dimensional density/histogram plots for flow data
Description
For flowSets the idea is to
horizontally stack plots of density estimates for all frames in the
flowSet for one or several flow parameters. In the latter case, each
parameter will be plotted in a separate panel, i.e., we implicitly condition
on parameters.
A formula describing the structure of the plot and the variables to
be used in the display. The structure of the formula is factor ~
parameter, where factor can be any of the phenotypic factors in the
phenoData slot or an appropriate factor object and parameter
is a flow parameter. Panels for multiple parameters are drawn if the formula
structure is similar to factor ~ parameter1 + parameter2, and
factor can be missing, in which case the sample names are used as
y-variable. To facilitate programatic access, the formula can be of special
structure factor ~ ., in which case the optional channel
argument is considered for parameter selection. For the workflow methods,
x can also be one of the several workflow objects.
data
A flow data object that serves as a source of data, either a
flowFrame or
flowSet
frames
An environment containing frame-specific data.
overlap
The amount of overlap between stacked density plots. This
argument is ignored for the flowFrame method.
subscripts,which.channel,channel.name,y
Internal indices necessary to
map panels to parameters.
darg
These arguments are passed unchanged to the corresponding
methods in lattice, and are listed here only because they provide different
defaults. See documentation for the original methods for details.
darg gets passed on to density.
channel
The name of the currently plotted flow parameter.
filter
A filter,
filterResult or
filterResultList object or a list
of such objects of the same length as the flowSet. If applicable, the
gate region will be superiposed on the density curves using color shading.
The software will figure out whether the filter needs to be evaluated
in order to be plotted (in which case providing a filterResult can
speed things up considerably).
col,fill,lty,lwd,alpha
Graphical parameters. These mostly exist for
conveniance and much more control is available throught the
lattice-like par.setting and flowViz.par.set
customization. The relevant parameter category for density plots is
gate.density with available parameters col, fill,
lwd, alpha and lty. See
flowViz.par.set for details.
groups
Use identical colors for grouping. The value of the argument
is expected to be a phenotypic variable in the flowSet, or a factor.
refline
Logical. Add one ore more vertical reference lines to the
plot. This argument is directly passed to
panel.abline.
margin
Either Logical value 'FALSE' or Numeric valuein [0,1].
When 'FALSE', it doesn't do anything to the margin events. When Numeric
value, it indicates margin events by horizontal bars. The value of
margin is interpreted as the proportion of events on the margin over
which the bars are added. E.g., a value of 0,5 means to indicate
margin events if there are more than 0.5 times the total number of
events. 1 means to ignore margin events completetly. For 0
bars are added even if there is only a single margin event.
stats,pos,digits,abs
Arguments to control statistics that is
associated with filter to be plotted.
see xyplot for details.
fitGate
A logical scalar indicating whether to display the
gate as fitted 1d density gate region or simply display the gate boundaries
using vertical lines. The latter would be helpful to display the gate when
the gated density region is too small to see.
checkName
A logical scalar indicating whether to validity
check the channel name. Default is TRUE, which consider '(' as invalid
character in channel names
plotType
either 'densityplot' or 'histogram'
hist.type
see 'type' argument in 'help(panel.histogram)'
breaks
see 'help(hist)'
gp
A list of graphical parameters that are passed down to the low
level panel functions. This is for internal use only. The public user
interface to set graphical parameters is either par.settings for
customization of a single call or flowViz.par.set for customization
of session-wide defaults.
overlay
see help(xyplot).
...
More arguments, usually passed on to the underlying lattice
methods.
channels A character vector of parameters that are supposed to be
plotted when the formula in x is of structure factor ~ ..
xlab: Label for data x axis, with suitable defaults taken from the
formula
prepanel: The prepanel function. See xyplot
panel: the panel function. See xyplot
axis: axis function passed to lattice, default is axis.grid
... : other arguments passed to panel.densityplot.flowset.stack or
panel.histogram.flowframe
Details
Not all standard lattice arguments will have the intended effect, but many
should. For a fuller description of possible arguments and their effects,
consult documentation on lattice (Trellis docs would also work for the
fundamentals).
Examples
library(flowStats)
data(GvHD)
GvHD <- GvHD[pData(GvHD)$Patient %in% 6:7]
densityplot(~ `FSC-H`, GvHD)
densityplot(~ `FSC-H` + `SSC-H`, GvHD)
densityplot(~ ., GvHD[1:3])
## include a filter
densityplot(~ `FSC-H`, GvHD, filter=curv1Filter("FSC-H"))
#display the gate by its boundaries with statistics
densityplot(~ `FSC-H`, GvHD[1:2], filter=curv1Filter("FSC-H"),fitGate=FALSE,stats=TRUE)
## plot a single flowFrame
densityplot(~ `SSC-H`, GvHD[[1]], margin=FALSE)
## plot histogram
histogram(~ `SSC-H`, GvHD[[1]]) #default type is 'density'
#change the type to 'count' and adjust breaks
histogram(~ `SSC-H`, GvHD[[1]], margin=FALSE, type = "count", breaks = 50)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(flowViz)
Loading required package: flowCore
Loading required package: lattice
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/flowViz/densityplot.Rd_%03d_medium.png", width=480, height=480)
> ### Name: densityplot
> ### Title: One-dimensional density/histogram plots for flow data
> ### Aliases: densityplot densityplot,formula,flowFrame-method
> ### densityplot,formula,flowSet-method densityplot,formula,view-method
> ### histogram,formula,flowFrame-method histogram,formula,flowSet-method
> ### panel.densityplot.flowset.stack prepanel.densityplot.flowset.stack
>
> ### ** Examples
>
> library(flowStats)
Loading required package: fda
Loading required package: splines
Loading required package: Matrix
Attaching package: 'Matrix'
The following object is masked from 'package:flowCore':
%&%
Attaching package: 'fda'
The following object is masked from 'package:graphics':
matplot
Loading required package: mvoutlier
Loading required package: sgeostat
sROC 0.1-2 loaded
Loading required package: cluster
Loading required package: flowWorkspace
Loading required package: ncdfFlow
Loading required package: RcppArmadillo
Loading required package: BH
Loading required package: gridExtra
> data(GvHD)
> GvHD <- GvHD[pData(GvHD)$Patient %in% 6:7]
>
> densityplot(~ `FSC-H`, GvHD)
>
> densityplot(~ `FSC-H` + `SSC-H`, GvHD)
>
> densityplot(~ ., GvHD[1:3])
>
> ## include a filter
> densityplot(~ `FSC-H`, GvHD, filter=curv1Filter("FSC-H"))
>
> #display the gate by its boundaries with statistics
> densityplot(~ `FSC-H`, GvHD[1:2], filter=curv1Filter("FSC-H"),fitGate=FALSE,stats=TRUE)
>
> ## plot a single flowFrame
> densityplot(~ `SSC-H`, GvHD[[1]], margin=FALSE)
>
> ## plot histogram
> histogram(~ `SSC-H`, GvHD[[1]]) #default type is 'density'
> #change the type to 'count' and adjust breaks
> histogram(~ `SSC-H`, GvHD[[1]], margin=FALSE, type = "count", breaks = 50)
>
>
>
>
>
> dev.off()
null device
1
>