Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

scale_fill_selection

ggplot2 helpers


Description

Add scale_fill_selection() or scale_color_selection to a ggplot to customize the scale for fill or color, respectively, for linked brushing. Use selection_factor to turn logical vectors representing selection, to a factor with the levels ordered for use with ggplot2 bar stacking.

Usage

scale_fill_selection(color_false, color_true)

scale_color_selection(color_false, color_true)

selection_factor(
  x,
  na.replace = c(FALSE, NA, TRUE),
  reverse = packageVersion("ggplot2") < "2.2.0"
)

Arguments

color_false

The color that should be mapped to unselected rows

color_true

The color that should be mapped to selected rows

x

Either a data frame with a selected_ column, or, a logical vector indicating which rows are selected

na.replace

The value to use to replace NA values; choose either FALSE, NA, or TRUE based on how you want values to be treated when no selection is active

reverse

Whether the factor level order should be c(FALSE, TRUE) (normal) or c(TRUE, FALSE) (reverse). The former is required for ggplot2 2.2.0+, the latter for earlier versions.

Examples

## Not run: 
sd <- SharedData$new(iris)
renderPlot({
  df <- sd$data(withSelection = TRUE, withFilter = TRUE)
  ggplot(df, aes(Sepal.Length, Sepal.Width,
    color = selection_factor(df))) +
    geom_point() +
    scale_color_selection("#444444", "skyblue1")
})


## End(Not run)

crosstalk

Inter-Widget Interactivity for HTML Widgets

v1.1.1
MIT + file LICENSE
Authors
Joe Cheng [aut], Carson Sievert [aut, cre] (<https://orcid.org/0000-0002-4958-2844>), RStudio [cph], jQuery Foundation [cph] (jQuery library and jQuery UI library), jQuery contributors [ctb, cph] (jQuery library; authors listed in inst/www/shared/jquery-AUTHORS.txt), Mark Otto [ctb] (Bootstrap library), Jacob Thornton [ctb] (Bootstrap library), Bootstrap contributors [ctb] (Bootstrap library), Twitter, Inc [cph] (Bootstrap library), Brian Reavis [ctb, cph] (selectize.js library), Kristopher Michael Kowal [ctb, cph] (es5-shim library), es5-shim contributors [ctb, cph] (es5-shim library), Denis Ineshin [ctb, cph] (ion.rangeSlider library), Sami Samhuri [ctb, cph] (Javascript strftime library)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.