Skip to content

Commit

Permalink
Merge pull request #1724 from rstudio/add-cols-nanoplot-example
Browse files Browse the repository at this point in the history
Add an example for the `cols_nanoplot()` function
  • Loading branch information
rich-iannone authored Jun 19, 2024
2 parents 0061af8 + 840fb09 commit 52c7cb7
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
93 changes: 92 additions & 1 deletion R/modify_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,97 @@ cols_add <- function(
#' median gives pretty useful information. Seems like customers preferred
#' getting the `"chicken"`-type pizzas in large size!
#'
#' Using the [`gibraltar`] dataset, let's make a series of nanoplots across the
#' meteorological parameters of temperature, humidity, and wind speed. We'll
#' want to customize the appearance of the plots across three columns and we
#' can make this somewhat simpler by assigning a common set of options through
#' [nanoplot_options()]. In this table we want to make comparisons across
#' nanoplots in a particular column easier, so, we'll set `autoscale = TRUE` so
#' that there is a common y-axis scale for each of the parameters (based on the
#' extents of the data).
#'
#' ```r
#' nanoplot_options_list <-
#' nanoplot_options(
#' data_point_radius = px(4),
#' data_point_stroke_width = px(2),
#' data_point_stroke_color = "black",
#' data_point_fill_color = "white",
#' data_line_stroke_width = px(4),
#' data_line_stroke_color = "gray",
#' show_data_line = TRUE,
#' show_data_points = TRUE,
#' show_data_area = FALSE,
#' )
#'
#' gibraltar |>
#' dplyr::filter(date <= "2023-05-14") |>
#' dplyr::mutate(time = as.numeric(hms::as_hms(paste0(time, ":00")))) |>
#' dplyr::mutate(humidity = humidity * 100) |>
#' dplyr::select(date, time, temp, humidity, wind_speed) |>
#' dplyr::group_by(date) |>
#' dplyr::summarize(
#' time = paste(time, collapse = ","),
#' temp = paste(temp, collapse = ","),
#' humidity = paste(humidity, collapse = ","),
#' wind_speed = paste(wind_speed, collapse = ","),
#' ) |>
#' dplyr::mutate(is_satsun = lubridate::wday(date) %in% c(1, 7)) |>
#' gt(rowname_col = "date") |>
#' tab_header(
#' title = "Meteorological Summary of Gibraltar Station",
#' subtitle = "Data taken from May 1-14, 2023."
#' ) |>
#' fmt_date(columns = stub(), date_style = "wd_m_day_year") |>
#' cols_nanoplot(
#' columns = temp,
#' columns_x_vals = time,
#' expand_x = c(0, 86400),
#' autoscale = TRUE,
#' new_col_name = "temperature_nano",
#' new_col_label = "Temperature",
#' options = nanoplot_options_list
#' ) |>
#' cols_nanoplot(
#' columns = humidity,
#' columns_x_vals = time,
#' expand_x = c(0, 86400),
#' autoscale = TRUE,
#' new_col_name = "humidity_nano",
#' new_col_label = "Humidity",
#' options = nanoplot_options_list
#' ) |>
#' cols_nanoplot(
#' columns = wind_speed,
#' columns_x_vals = time,
#' expand_x = c(0, 86400),
#' autoscale = TRUE,
#' new_col_name = "wind_speed_nano",
#' new_col_label = "Wind Speed",
#' options = nanoplot_options_list
#' ) |>
#' cols_units(
#' temperature_nano = ":degree:C",
#' humidity_nano = "% (RH)",
#' wind_speed_nano = "m s^-1"
#' ) |>
#' cols_hide(columns = is_satsun) |>
#' tab_style_body(
#' style = cell_fill(color = "#E5FEFE"),
#' values = TRUE,
#' targets = "row",
#' extents = c("body", "stub")
#' ) |>
#' tab_style(
#' style = cell_text(align = "center"),
#' locations = cells_column_labels()
#' )
#' ```
#'
#' \if{html}{\out{
#' `r man_get_image_tag(file = "man_cols_nanoplot_6.png")`
#' }}
#'
#' Box plots can be generated, and we just need to use `plot_type = "boxplot"`
#' to make that type of nanoplot. Using a small portion of the [`pizzaplace`]
#' dataset, we will create a simple table that displays a box plot of pizza
Expand Down Expand Up @@ -2694,7 +2785,7 @@ cols_add <- function(
#' ```
#'
#' \if{html}{\out{
#' `r man_get_image_tag(file = "man_cols_nanoplot_6.png")`
#' `r man_get_image_tag(file = "man_cols_nanoplot_7.png")`
#' }}
#'
#' @family column modification functions
Expand Down
Binary file modified images/man_cols_nanoplot_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/man_cols_nanoplot_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 91 additions & 1 deletion man/cols_nanoplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52c7cb7

Please sign in to comment.