This is an alternate to the plot_density() function using base graphics.
The advantage of this function is that it should work with most matrix-like
objects. This is especially helpful for DelayedArrays, which
plot_density() does not handle.
Usage
plot_density2(
  x,
  metadata = NULL,
  col_by = NULL,
  hcl_palette = "Zissou",
  plot_title = NULL,
  x_label = "",
  y_label = "Density",
  legend_position = "topright",
  line_weight = 1,
  line_type = 1,
  ...
)Arguments
- x
 feature x sample matrix or matrix-like object
- metadata
 data.frame containing metadata per sample. rownames of metadata must match the colnames of the input matrix. Default NULL, each sample in the matrix will be plotted.
- col_by
 metadata column used to color density lines. Default NULL, each sample in the matrix will be plotted.
- hcl_palette
 color palette applied to 'col_by' variable. One of the
hcl.pals(). Default "Zissou"- plot_title
 title of the plot. Default NULL
- x_label
 x-axis title. Default ""
- y_label
 y-axis title. Default "Density"
- legend_position
 location keyword for the legend. One of "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center". Default "topright"
- line_weight
 line weight of the density lines. Default 1
- line_type
 line type of the density lines. Default 1
- ...
 Additional arguments not currently used.
Examples
# Create metadata for plotting
metadata <- data.frame(row.names = colnames(GSE161650_lc))
metadata$Group <- rep(c("DMSO", "THZ1"), each = 3)
# Plot the density by sample
plot_density2(GSE161650_lc)
# Color each sample by their Group in metadata
plot_density2(
  GSE161650_lc,
  metadata,
  col_by = "Group",
  x_label = "log2 CPMs",
  plot_title = "Distribution of logCPM values"
  )