SomaLogic / SomaPlotr

A highly specialized suite of standardized plotting routines based on the "Grammar of Graphics" framework of mapping variables to aesthetics used in 'ggplot2'. Graphics types are biased towards visualizing SomaScan (proteomic) data.
https://somalogic.github.io/SomaPlotr/
Other
3 stars 4 forks source link

Add grouping capability to boxplotSubarray() #24

Closed amanda-hi closed 11 months ago

amanda-hi commented 11 months ago

Note: This issue/feature request was originally made by Eshita Mutt from GSE on Nov 17th, 2023

Checks

Problem and/or Feature

Is it possible to add group.var = c("SampleType", "PlateId"), as possible in boxplotGrouped()? From the vignettes, there isn't evidence of this functionality for boxplotSubarray(). Primarily, the goal is to make boxplots for all analytes (log10) and group by SampleType & then color by PlateId.

There are two potential methods to group a boxplotSubarray() plot:

  1. Use facet_wrap() or facet_grid() to split the plot by a variable of interest. This will not require the addition of a new argument to boxplotSubarray(), and will utilize already-available ggplot2 functions. The problem: Metadata variables can't currently be used to group a plot made by boxplotSubarray() via facet_*() because the unused metadata columns are stripped away internally before the final plot is produced.

Example:

reprex::reprex({
  suppressPackageStartupMessages({
    library(SomaDataIO)
    library(SomaPlotr)
    library(ggplot2)
  })

  p <- boxplotSubarray(SomaDataIO::example_data, color.by = "PlateId", do.log = TRUE)
  p + facet_wrap(~PlateId) # Produces an error, `PlateId` isn't found

  colnames(p$data) # PlateId is not present in plot data
})
  1. Add an argument to boxplotSubarray() that will instruct the function to group based on the specified variable. This variable can then be retained when the plot data object is made, and should resolve the variable not found error produced when using facet_wrap(). The problem: this can already be accomplished by adding a facet_*() layer to the plot.

Example:

boxplotSubarray(SomaDataIO::example_data, color.by = "SampleType", group.by = "PlateId", do.log = TRUE)

Priority Level


Thanks for contributing :partying_face:!

stufield commented 11 months ago

I think I like Option #1 above ... with perhaps a new example in the docs.