Skip to content

Positive and negative horizontal-barplot nanoplots #1515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 23, 2023

Conversation

rich-iannone
Copy link
Member

The changes here allow for nanoplots that are essentially single-valued bars (when plot_type = "bar" and there is just a single value to plot) to display in positive and negative directions. A zero-value line marker is now displayed. Negative values have a different color (obtained from the data_bar_negative_stroke_color arg in nanoplot_options()) and other settable display attributes.

Here are some examples:

library(tidyverse)
library(gt)

# Positive, zero-value, NA
dplyr::tibble(
  a = c(4.6, 0.2, 5.6, 6.3, 0, NA)
) |>
  gt() |>
  cols_nanoplot(columns = a, plot_type = "bar") |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
example-1
# Negative, zero-value, NA
dplyr::tibble(
  a = c(-4.6, -0.2, -5.6, -6.3, 0, NA)
) |>
  gt() |>
  cols_nanoplot(columns = a, plot_type = "bar") |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
example-2
# Positive, zero-value, negative 
dplyr::tibble(
  a = c(-20, -10, 0, 10, 5)
) |>
  gt() |>
  cols_nanoplot(columns = a, plot_type = "bar") |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
example-3
# All zero nanoplots
dplyr::tibble(
  a = c(0, 0, 0, 0, 0)
) |>
  gt() |>
  cols_nanoplot(columns = a, plot_type = "bar") |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
example-4
# Constant non-zero value (positive)
dplyr::tibble(
  a = c(5, 5, 5, 5, 5)
) |>
  gt() |>
  cols_nanoplot(columns = a, plot_type = "bar") |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
example-5
# Constant non-zero value (negative)
dplyr::tibble(
  a = c(-5, -5, -5, -5, -5)
) |>
  gt() |>
  cols_nanoplot(columns = a, plot_type = "bar") |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
example-6
# Single value bars combined with multiple bars
dplyr::tibble(
  a = c(4.6, 0.2, 5.6, "3.4,-2.4,7.8,1.2,-6.8,0,2.4,-7.4,5.2", 6.3, 0, NA)
) |>
  gt() |>
  cols_nanoplot(columns = a, plot_type = "bar") |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
example-7

@rich-iannone rich-iannone merged commit 3753c5f into master Dec 23, 2023
@rich-iannone rich-iannone deleted the nanoplots-the-revenge branch December 23, 2023 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant