tidymodels / shinymodels

https://shinymodels.tidymodels.org/
Other
46 stars 5 forks source link

work with NULL mappings #31

Closed topepo closed 3 years ago

topepo commented 3 years ago

The function maybe_modify_mapping() adds a new aesthetic mapping to an existing ggplot object.

There is a bug where, for some autoplot() results, the mapping that we want to modify is NULL:

maybe_modify_mapping <- function(x) {
  has_mapping <- any(names(x) == "mapping")
  is_point <- is_geom_point(x)
  is_null <- identical(x$mapping, NULL).  #<- currently skip null mappings
  if (has_mapping & is_point & !is_null) {
    x$mapping <- utils::modifyList(x$mapping, ggplot2::aes(customdata = .config))
  }
  x
}

If there is a geom_point() with a local NULL mapping, we should make a new mapping with customdata = .config.

adhikars11 commented 3 years ago

Modifying the function to the following solves the issue:

maybe_modify_mapping <- function(x) {
  has_mapping <- any(names(x) == "mapping")
  is_point <- is_geom_point(x)
  if (has_mapping & is_point) {
    x$mapping <- utils::modifyList(
      x$mapping %||% list(),
      ggplot2::aes(customdata = .config)
    )
  }
  x
}
github-actions[bot] commented 1 year ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.