Skip to content

Commit

Permalink
Merge pull request #1527 from rstudio/nanoplot-boxplot
Browse files Browse the repository at this point in the history
Add the `"boxplot"` type of nanoplot
  • Loading branch information
rich-iannone authored Jan 6, 2024
2 parents cdcd706 + c19023d commit c1ed008
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 47 deletions.
43 changes: 24 additions & 19 deletions R/modify_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -2154,16 +2154,16 @@ cols_add <- function(
#' the `options` argument). A guide on the left-hand side of the plot area will
#' appear on hover and display the minimal and maximal *y* values.
#'
#' There are two types of nanoplots available: `"line"` and `"bar"`. A line plot
#' shows individual data points and has smooth connecting lines between them to
#' allow for easier scanning of values. You can opt for straight-line
#' connections between data points, or, no connections at all (it's up to you).
#' You can even eschew the data points and just have a simple line. Regardless
#' of how you mix and match difference plot layers, the plot area focuses on the
#' domain of the data points with the goal of showing you the overall trend of
#' the data. The data you feed into a line plot can consist of a single vector
#' of values (resulting in equally-spaced *y* values), or, you can supply two
#' vectors representative of *x* and *y*.
#' There are three types of nanoplots available: `"line"`, `"bar"`, `"boxplot"`.
#' A line plot shows individual data points and has smooth connecting lines
#' between them to allow for easier scanning of values. You can opt for
#' straight-line connections between data points, or, no connections at all
#' (it's up to you). You can even eschew the data points and just have a simple
#' line. Regardless of how you mix and match difference plot layers, the plot
#' area focuses on the domain of the data points with the goal of showing you
#' the overall trend of the data. The data you feed into a line plot can consist
#' of a single vector of values (resulting in equally-spaced *y* values), or,
#' you can supply two vectors representative of *x* and *y*.
#'
#' A bar plot is built a little bit differently. The focus is on evenly-spaced
#' bars (requiring a single vector of values) that project from a zero line,
Expand All @@ -2173,6 +2173,10 @@ cols_add <- function(
#' each. A guide on the left-hand side of the plot area will display the minimal
#' and maximal *y* values on hover.
#'
#' Every box plot will take the collection of values for a row and construct the
#' plot horizontally. This is essentially a standard box-and-whisker diagram
#' where outliers are automatically displayed outside the left and right fences.
#'
#' While basic customization options are present in the `cols_nanoplot()`, many
#' more opportunities for customizing nanoplots on a more granular level are
#' possible with the [nanoplot_options()] helper function. That function should
Expand Down Expand Up @@ -2208,15 +2212,16 @@ cols_add <- function(
#'
#' @param plot_type *The type of nanoplot to display*
#'
#' `singl-kw:[line|bar]` // *default:* `"line"`
#' `singl-kw:[line|bar|boxplot]` // *default:* `"line"`
#'
#' Nanoplots can either take the form of a line plot (using `"line"`) or a bar
#' plot (with `"bar"`). A line plot, by default, contains layers for a data
#' line, data points, and a data area. Each of these can be deactivated by
#' using [nanoplot_options()]. With a bar plot, the always visible layer is
#' that of the data bars. Furthermore, a line plot can optionally take in *x*
#' values through the `columns_x_vals` argument whereas a bar plot ignores any
#' data representing the independent variable.
#' Nanoplots can either take the form of a line plot (using `"line"`), a bar
#' plot (with `"bar"`), or a box plot (`"boxplot"`). A line plot, by default,
#' contains layers for a data line, data points, and a data area. Each of
#' these can be deactivated by using [nanoplot_options()]. With a bar plot,
#' the always visible layer is that of the data bars. Furthermore, a line plot
#' can optionally take in *x* values through the `columns_x_vals` argument
#' whereas bar plots and box plots both ignore any data representing the
#' independent variable.
#'
#' @param plot_height *The height of the nanoplots*
#'
Expand Down Expand Up @@ -2679,7 +2684,7 @@ cols_nanoplot <- function(
data,
columns,
rows = everything(),
plot_type = c("line", "bar"),
plot_type = c("line", "bar", "boxplot"),
plot_height = "2em",
missing_vals = c("gap", "zero", "remove"),
autoscale = FALSE,
Expand Down
Loading

0 comments on commit c1ed008

Please sign in to comment.