dittoPlot {dittoSeq} | R Documentation

## Plots continuous data for cutomizable cells'/samples' groupings on a y-axis

### Description

Plots continuous data for cutomizable cells'/samples' groupings on a y-axis

### Usage

    dittoPlot(
      object,
      var,
      group.by,
      color.by = group.by,
      shape.by = NULL,
      split.by = NULL,
      extra.vars = NULL,
      cells.use = NULL,
      plots = c("jitter", "vlnplot"),
      assay = .default_assay(object),
      slot = .default_slot(object),
      adjustment = NULL,
      do.hover = FALSE,
      hover.data = var,
      color.panel = dittoColors(),
      colors = seq_along(color.panel),
      shape.panel = c(16, 15, 17, 23, 25, 8),
      theme = theme_classic(),
      main = "make",
      sub = NULL,
      ylab = "make",
      y.breaks = NULL,
      min = NULL,
      max = NULL,
      xlab = group.by,
      x.labels = NULL,
      x.labels.rotate = NA,
      x.reorder = NULL,
      split.nrow = NULL,
      split.ncol = NULL,
      jitter.size = 1,
      jitter.width = 0.2,
      jitter.color = "black",
      jitter.shape.legend.size = NA,
      jitter.shape.legend.show = TRUE,
      boxplot.width = 0.2,
      boxplot.color = "black",
      boxplot.show.outliers = NA,
      boxplot.fill = TRUE,
      vlnplot.lineweight = 1,
      vlnplot.width = 1,
      vlnplot.scaling = "area",
      ridgeplot.lineweight = 1,
      ridgeplot.scale = 1.25,
      add.line = NULL,
      line.linetype = "dashed",
      line.color = "black",
      legend.show = TRUE,
      legend.title = "make",
      data.out = FALSE
    )

    dittoRidgePlot(..., plots = c("ridgeplot"))

    dittoRidgeJitter(..., plots = c("ridgeplot", "jitter"))

    dittoBoxPlot(..., plots = c("boxplot", "jitter"))

### Arguments

`object` | A Seurat or SingleCellExperiment object to work with
`var` | Single string representing the name of a metadata or gene, OR a vector with length equal to the total number of cells/samples in the dataset. This is the data that will be displayed.
`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 `group.by` so this input can be skipped otherwise. Affects boxplot, vlnplot, and ridgeplot fills.
`shape.by` | Single string representing the name of a metadata to use for setting the shapes of the jitter points. When not provided, all cells/samples will be represented with dots.
`split.by` | 1 or 2 strings naming discrete metadata to use for splitting the cells/samples into multiple plots with ggplot faceting. When 2 metadatas are named, c(row,col), the first is used as rows and the second is used for columns of the resulting grid. When 1 metadata is named, shape control can be achieved with `split.nrow` and `split.ncol`
`extra.vars` | String vector providing names of any extra metadata to be stashed in the dataframe supplied to `ggplot(data)`. Useful for making custom spliting/faceting or other additional alterations after dittoSeq plot generation.
`cells.use` | String vector of cells'/samples' names 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. For the typically easier logical method, provide `USE` in `colnames(object)[USE]` OR `object@cell.names[USE]`.
`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 gene expression / feature data. See `gene` for more information.
`adjustment` | When plotting gene expression / feature counts, should that data be used directly (default) or should it be adjusted to be "z-score": scaled with the scale() function to produce a relative-to-mean z-score representation "relative.to.max": divided by the maximum expression value to give percent of max values between [0,1]
`do.hover` | Logical. Default = `FALSE`. If set to `TRUE` (and if there is a "jitter" in `plots`): object will be converted to a ggplotly object so that data about individual cells will be displayed when you hover your cursor over the jitter points, Note: Currently, hovering is incompatible with RidgePlots as plotly does not support the ggplot geom.
`hover.data` | String vector, a list of variable names, c("meta1","gene1","meta2",...) which determines what data to show upon hover when do.hover is set to `TRUE`.
`color.panel` | String vector which sets the colors to draw from for plot fills. Default = `dittoColors()`.
`colors` | Integer vector, the indexes / order, of colors from color.panel to actually use. (Provides an alternative to directly modifying `color.panel`.)
`shape.panel` | Vector of integers corresponding to ggplot shapes which sets what shapes to use. When discrete groupings are supplied by `shape.by`, this sets the panel of shapes which will be used. When nothing is supplied to `shape.by`, only the first value is used. Default is a set of 6, `c(16,15,17,23,25,8)`, the first being a simple, solid, circle.
`theme` | A ggplot theme which will be applied before dittoSeq adjustments. Default = `theme_classic()`. See https://ggplot2.tidyverse.org/reference/ggtheme.html for other options and ideas.
`main` | String, sets the plot title. Default = "make" and if left as make, a title will be automatically generated. To remove, set to `NULL`.
`sub` | String, sets the plot subtitle
`ylab` | String, sets the continuous-axis label (=y-axis for box and violin plots, x-axis for ridgeplots). Defaults to "`var`" or "`var` expression" if `var` is a gene.
`y.breaks` | Numeric vector, a set of breaks that should be used as major gridlines. 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. Default = set based on the limits of the data in var.
`xlab` | String which sets the grouping-axis label (=x-axis for box and violin plots, y-axis for ridgeplots). Default is `group.by` so it defaults to the name of the grouping information. Set to `NULL` to remove.
`x.labels` | String vector, c("label1","label2","label3",...) which overrides the names of the samples/groups. NOTE: you need to give at least as many labels as there are discrete values in the group.by data.
`x.labels.rotate` | Logical which sets whether the labels should be rotated. Default: `TRUE` for violin and box plots, but `FALSE` for ridgeplots.
`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.
`split.nrow, split.ncol` | Integers which set the dimensions of faceting/splitting when a single metadata is given to `split.by`.
`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
`jitter.shape.legend.size` | Scalar which changes the size of the shape key in the legend. If set to `NA`, `jitter.size` is used.
`jitter.shape.legend.show` | Logical which sets whether the shapes legend will be shown when its shape is determined by `shape.by`.
`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 `FALSE` when there is a jitter plotted, `TRUE` if there is no jitter.
`boxplot.fill` | Logical, whether the boxplot should be filled in or not. Known bug: when boxplot fill is turned off, outliers do not render.
`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 `geom_violin`.
`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
`add.line` | numeric value(s) where one or multiple line should be added
`line.linetype` | String which sets the type of line for `add.line`. Defaults to "dashed", but any ggplot linetype will work.
`line.color` | String that sets the color(s) of the `add.line` line(s)
`legend.show` | Logical. Whether the legend should be displayed. Default = `TRUE`.
`legend.title` | String or `NULL`, sets the title for the main legend which includes colors and data representations. This input is set to `NULL` by default.
`data.out` | Logical. When set to `TRUE`, changes the output, from the plot alone, to a list containing the plot (`p`) and data (`data`). Note: plotly conversion is turned off in the `data.out = TRUE` setting, but hover.data is still calculated.
`...` | arguments passed to dittoPlot by dittoRidgePlot, dittoRidgeJitter, and dittoBoxPlot wrappers. Options are all the ones above.

### Details

The function creates a dataframe containing the metadata or expression data associated with the given `var` (or if a vector of data is provided, that data). On the discrete axis, data will be grouped by the metadata given to `group.by` and colored by the metadata given to `color.by`. The `assay` and `slot` inputs can be used to change what expression data is used when displaying gene expression. If a set of cells to use is indicated with the `cells.use` input, the data is subset to include only those cells before plotting.

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"`. Inclusion of `"ridgeplot"` overrides boxplot and violin plot and changes the plot to be horizontal.

When `split.by` is provided the name of a metadata containing discrete data, separate plots will be produced representing each of the distinct groupings of the split.by data.

`dittoRidgePlot`, `dittoRidgeJitter`, and `dittoBoxPlot` are included as wrappers of the basic `dittoPlot` function that simply change the default for the `plots` input to be `"ridgeplot"`, `c("ridgeplot","jitter")`, or `c("boxplot","jitter")`, to make such plots even easier to produce.

### Value

a ggplot or plotly where continuous data, grouped by sample, age, cluster, etc., shown on either the y-axis by a violin plot, boxplot, and/or jittered points, or on the x-axis by a ridgeplot with or without jittered points.

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.

### Functions

- `dittoRidgePlot`: Plots continuous data for cutomizable cells'/samples' groupings horizontally in a density representation

- `dittoRidgeJitter`: dittoRidgePlot, but with jitter overlaid

- `dittoBoxPlot`: Plots continuous data for cutomizable cells'/samples' groupings in boxplot form

### Many characteristics of the plot can be adjusted using discrete inputs

- Each data representation has options which are controlled by variables that start with their associated string. For example, all jitter adjustments, like `jitter.size`, start with "`jitter.`".

- 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.

- Single or multiple additional per-cell features can be retrieved and stashed within the underlying data using `extra.vars`. This can be very useful for making manual additional alterations after dittoSeq plot generation.

### Author(s)

Daniel Bunis

### See Also

`multi_dittoPlot` for easy creation of multiple dittoPlots each focusing on a different `var`.

`dittoPlotVarsAcrossGroups` to create dittoPlots that show summarized expression (or values for metadata), accross groups, of multiple `vars` in a single plot.

`dittoRidgePlot`, `dittoRidgeJitter`, and `dittoBoxPlot` for shortcuts to a few 'plots' input shortcuts

### Examples

    # dittoSeq handles bulk and single-cell data quit similarly.
    # The SingleCellExperiment object structure is used for both,
    # but all functions can be used similarly directly on Seurat
    # objects as well.

    example(importDittoBulk, echo = FALSE)
    myRNA

    # Basic dittoplot, with jitter behind a vlnplot (looks better with more cells)
    dittoPlot(object = myRNA, var = "gene1", group.by = "timepoint")

    # Color distinctly from the grouping variable using 'color.by'
    dittoPlot(object = myRNA, var = "gene1", group.by = "timepoint",
        color.by = "conditions")

    # Update the 'plots' input to change / reorder the data representations
    dittoPlot(myRNA, "gene1", "timepoint",
        plots = c("vlnplot", "boxplot", "jitter"))

    # Modify the look with intuitive inputs
    dittoPlot(myRNA, "gene1", "timepoint",
        plots = c("vlnplot", "boxplot", "jitter"),
        boxplot.color = "white",
        main = "CD3E",
        legend.show = FALSE)

    # Data can also be split in other ways with 'shape.by' or 'split.by'
    dittoPlot(object = myRNA, var = "gene1", group.by = "timepoint",
        plots = c("vlnplot", "boxplot", "jitter"),
        shape.by = "clustering",
        split.by = "SNP") # single split.by element
    dittoPlot(object = myRNA, var = "gene1", group.by = "timepoint",
        plots = c("vlnplot", "boxplot", "jitter"),
        split.by = c("groups","SNP")) # row and col split.by elements

    # For faceting, instead of using 'split.by', the target data can alternatively
    # be given to 'extra.var' to have it added in the underlying dataframe, then
    # faceting can be added manually for extra flexibility
    dittoPlot(myRNA, "gene1", "clustering",
        plots = c("vlnplot", "boxplot", "jitter"),
        extra.var = "SNP") + facet_wrap("SNP", ncol = 1, strip.position = "left")

    # Quickly make a Ridgeplot
    dittoRidgePlot(myRNA, "gene1", group.by = "timepoint")

    # Quickly make a Boxplot
    dittoBoxPlot(myRNA, "gene1", group.by = "timepoint")

[Package dittoSeq version 1.0.2 Index]