Description Usage Arguments Details Value Plot Customization Author(s) See Also Examples
View source: R/dittoPlotVarsAcrossGroups.R
Generates a dittoPlot where data points are genes/metadata summaries, per groups, instead of individual values per cells/samples.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | dittoPlotVarsAcrossGroups(
object,
vars,
group.by,
color.by = group.by,
summary.fxn = mean,
cells.use = NULL,
plots = c("vlnplot", "jitter"),
assay = .default_assay(object),
slot = .default_slot(object),
adjustment = "z-score",
do.hover = FALSE,
main = NULL,
sub = NULL,
ylab = "make",
y.breaks = NULL,
min = NULL,
max = NULL,
xlab = group.by,
x.labels = NULL,
x.labels.rotate = NA,
x.reorder = NULL,
color.panel = dittoColors(),
colors = c(seq_along(color.panel)),
theme = theme_classic(),
jitter.size = 1,
jitter.width = 0.2,
jitter.color = "black",
do.raster = FALSE,
raster.dpi = 300,
boxplot.width = 0.2,
boxplot.color = "black",
boxplot.show.outliers = NA,
boxplot.fill = TRUE,
boxplot.position.dodge = vlnplot.width,
vlnplot.lineweight = 1,
vlnplot.width = 1,
vlnplot.scaling = "area",
ridgeplot.lineweight = 1,
ridgeplot.scale = 1.25,
ridgeplot.ymax.expansion = NA,
add.line = NULL,
line.linetype = "dashed",
line.color = "black",
legend.show = TRUE,
legend.title = NULL,
data.out = FALSE
)
|
object |
A Seurat, SingleCellExperiment, or SummarizedExperiment object. |
vars |
String vector (example: |
group.by |
String representing the name of a metadata to use for separating the cells/samples into discrete groups. |
color.by |
String representing the name of a metadata to use for setting fills.
Great for highlighting subgroups when wanted, but it defaults to |
summary.fxn |
A function which sets how variables' data will be summarized across the groups.
Default is |
cells.use |
String vector of cells'/samples' names OR an integer vector specifying the indices of cells/samples which should be included. Alternatively, a Logical vector, the same length as the number of cells in the object, which sets which cells to include. |
plots |
String vector which sets the types of plots to include: possibilities = "jitter", "boxplot", "vlnplot", "ridgeplot". Order matters: c("vlnplot", "boxplot", "jitter") will put a violin plot in the back, boxplot in the middle, and then individual dots in the front. See details section for more info. |
assay, slot |
single strings or integer that set which data to use when plotting expressin data. See |
adjustment |
When plotting gene expression (or antibody, or other forms of counts data), should that data be used directly or should it be adjusted to be
|
do.hover |
Logical. Default = Note: Currently, plotly is incompatible with ridge plots as plotly does not support the geom_density_ridges2 geom. |
main |
String which sets the plot title. |
sub |
String which sets the plot subtitle. |
ylab |
String which sets the y axis label.
Default = a combination of the name of the summary function + |
y.breaks |
Numeric vector, a set of breaks that should be used as major grid lines. c(break1,break2,break3,etc.). |
min, max |
Scalars which control the zoom of the plot. These inputs set the minimum / maximum values of the data to show. |
xlab |
String which sets the grouping-axis label (=x-axis for box and violin plots, y-axis for ridgeplots).
Set to |
x.labels |
String vector, c("label1","label2","label3",...) which overrides the names of the samples/groups. |
x.labels.rotate |
Logical which sets whether the labels should be rotated.
Default: |
x.reorder |
Integer vector. A sequence of numbers, from 1 to the number of groupings, for rearranging the order of x-axis groupings. Method: Make a first plot without this input. Then, treating the leftmost grouping as index 1, and the rightmost as index n. Values of x.reorder should be these indices, but in the order that you would like them rearranged to be. Recommendation for advanced users: If you find yourself coming back to this input too many times, an alternative solution that can be easier long-term
is to make the target data into a factor, and to put its levels in the desired order: |
color.panel |
String vector which sets the colors to draw from for plot fills. |
colors |
Integer vector, the indexes / order, of colors from color.panel to actually use.
(Provides an alternative to directly modifying |
theme |
A ggplot theme which will be applied before dittoSeq adjustments.
Default = |
jitter.size |
Scalar which sets the size of the jitter shapes. |
jitter.width |
Scalar that sets the width/spread of the jitter in the x direction. Ignored in ridgeplots. |
jitter.color |
String which sets the color of the jitter shapes |
do.raster |
Logical. When set to |
raster.dpi |
Number indicating dots/pixels per inch (dpi) to use for rasterization. Default = 300. |
boxplot.width |
Scalar which sets the width/spread of the boxplot in the x direction |
boxplot.color |
String which sets the color of the lines of the boxplot |
boxplot.show.outliers |
Logical, whether outliers should by including in the boxplot.
Default is |
boxplot.fill |
Logical, whether the boxplot should be filled in or not. Known bug: when boxplot fill is turned off, outliers do not render. |
boxplot.position.dodge |
Scalar which adjusts the distance between boxplots when multiple are drawn per grouping (a.k.a. when |
vlnplot.lineweight |
Scalar which sets the thickness of the line that outlines the violin plots. |
vlnplot.width |
Scalar which sets the width/spread of the jitter in the x direction |
vlnplot.scaling |
String which sets how the widths of the of violin plots are set in relation to eachother.
Options are "area", "count", and "width". If the deafult is not right for your data, I recommend trying "width".
For a detailed explanation of each, see |
ridgeplot.lineweight |
Scalar which sets the thickness of the ridgeplot outline. |
ridgeplot.scale |
Scalar which sets the distance/overlap between ridgeplots. A value of 1 means the tallest density curve just touches the baseline of the next higher one. Higher numbers lead to greater overlap. Default = 1.25 |
ridgeplot.ymax.expansion |
Scalar which adjusts the minimal space between the topmost grouping and the top of the plot in order to ensure the curve is not cut off by the plotting grid. The larger the value, the greater the space requested. When left as NA, dittoSeq will attempt to determine an ideal value itself based on the number of groups & linear interpolation between these goal posts: #groups of 3 or fewer: 0.6; #groups=12: 0.1; #groups or 34 or greater: 0.05. |
add.line |
numeric value(s) where one or multiple line should be added |
line.linetype |
String which sets the type of line for |
line.color |
String that sets the color(s) of the |
legend.show |
Logical. Whether the legend should be displayed. Default = |
legend.title |
String or |
data.out |
Logical. When set to Note: plotly conversion is turned off in the |
Generally, this function will output a dittoPlot where each data point represents a gene (or metadata) rather than a cell/sample.
Values are the summary (mean
by default) of the values for each gene or metadata requested with vars
, within each group set by group.by
.
To start with, the data for each element of vars
is obtained.
When elements are genes/features, assay
and slot
are utilized to determine which expression data to use,
and adjustment
determines if and how the expression data might be adjusted.
By default, a z-score adjustment is applied to all gene/feature vars
.
Note that this adjustment is applied before cells/samples subsetting.
x-axis groupings are then determined using group.by
, and data for each variable is summarized using the summary.fxn
.
Finally, data is plotted with the data representation types in plots
.
a ggplot object
Alternatively when data.out = TRUE
, a list containing the plot ("p") and the underlying data as a dataframe ("data").
Alternatively when do.hover = TRUE
, a plotly converted version of the plot where additional data will be displayed when the cursor is hovered over jitter points.
The plots
argument determines the types of data representation that will be generated, as well as their order from back to front.
Options are "jitter"
, "boxplot"
, "vlnplot"
, and "ridgeplot"
.
Each plot type has specific associated options which are controlled by variables that start with their associated string, ex: jitter.size
.
Inclusion of "ridgeplot"
overrides boxplot and violin plot and changes the plot to be horizontal.
Colors can be adjusted with color.panel
.
Shapes used in conjunction with shape.by
can be adjusted with shape.panel
.
Titles and axes labels can be adjusted with main
, sub
, xlab
, ylab
, and legend.title
arguments.
The legend can be hidden by setting legend.show = TRUE
.
y-axis zoom and tick marks can be adjusted using min
, max
, and y.breaks
.
x-axis labels and groupings can be changed / reordered using x.labels
and x.reorder
, and rotation of these labels can be turned off with x.labels.rotate = FALSE
.
Line(s) can be added at single or multiple value(s) by providing these values to add.line
.
Linetype and color are set with line.linetype
, which is "dashed" by default, and line.color
, which is "black" by default.
Daniel Bunis
dittoPlot
and multi_dittoPlot
for plotting of single or mutliple expression and metadata vars, each as separate plots, on a per cell/sample basis.
dittoDotPlot
for an alternative representation of per-group summaries of multiple vars where all vars are displayed separately, but still in a single plot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | example(importDittoBulk, echo = FALSE)
# Pick a set of genes
genes <- getGenes(myRNA)[1:30]
dittoPlotVarsAcrossGroups(
myRNA, genes, group.by = "timepoint")
# Color can be controlled separately from grouping with 'color.by'
# Just note: all groupings must map to a single color.
dittoPlotVarsAcrossGroups(myRNA, genes, "timepoint",
color.by = "conditions")
# To change it to have the violin plot in the back, a jitter on
# top of that, and a white boxplot with no fill in front:
dittoPlotVarsAcrossGroups(myRNA, genes, "timepoint",
plots = c("vlnplot","jitter","boxplot"),
boxplot.color = "white",
boxplot.fill = FALSE)
## Data can be summarized in other ways by changing the summary.fxn input.
# median
dittoPlotVarsAcrossGroups(myRNA, genes, "timepoint",
summary.fxn = median,
adjustment = NULL)
# Percent non-zero expression ( = boring for this fake data)
percent <- function(x) {sum(x!=0)/length(x)}
dittoPlotVarsAcrossGroups(myRNA, genes, "timepoint",
summary.fxn = percent,
adjustment = NULL)
# To investigate the identities of outlier genes, we can turn on hovering
# (if the plotly package is available)
if (requireNamespace("plotly", quietly = TRUE)) {
dittoPlotVarsAcrossGroups(
myRNA, genes, "timepoint",
do.hover = TRUE)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.