Skip to content

Commit

Permalink
add spruce bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sheridar committed Sep 19, 2024
1 parent b0e6a39 commit 529036d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
23 changes: 14 additions & 9 deletions R/scale-spruce.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,26 @@ ggplot_add.ScaleDiscreteSpruce <- function(object, plot, object_name) {
is_spruce <- methods::is(scale, "ScaleDiscreteSpruce")

# Adjust colors from previous scale
# * only merge palettes if prev_scale is discrete
# * first apply pal function from prev scale to generate color palette
if (any(prev_aes) && is_spruce) {
prev_pal <- self$scales[prev_aes][[1]]$palette
spruce_pal <- scale$spruce_palette
prev_scale <- self$scales[[prev_aes]]

new_pal <- function(n) {
values <- prev_pal(n)
pal <- spruce_pal(n, values)
if (inherits(prev_scale, "ScaleDiscrete")) {
prev_pal <- prev_scale$palette
spruce_pal <- scale$spruce_palette

pal
}
new_pal <- function(n) {
values <- prev_pal(n)
pal <- spruce_pal(n, values)

self$scales[prev_aes][[1]]$palette <- new_pal
pal
}

scale <- NULL
self$scales[prev_aes][[1]]$palette <- new_pal

scale <- NULL
}

} else if (any(prev_aes)) {
# Get only the first aesthetic name in the returned vector -- it can
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ knitr::opts_chunk$set(
# ggspruce

<!-- badges: start -->
[![Codecov test coverage](https://codecov.io/gh/sheridar/ggspruce/graph/badge.svg)](https://app.codecov.io/gh/sheridar/ggspruce)
[![R-CMD-check](https://github.com/sheridar/ggspruce/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sheridar/ggspruce/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/sheridar/ggspruce/graph/badge.svg)](https://app.codecov.io/gh/sheridar/ggspruce)
<!-- badges: end -->

ggspruce provides functions that make automatic adjustments to ggplot2 plots
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

<!-- badges: start -->

[![R-CMD-check](https://github.com/sheridar/ggspruce/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sheridar/ggspruce/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/sheridar/ggspruce/graph/badge.svg)](https://app.codecov.io/gh/sheridar/ggspruce)
[![R-CMD-check](https://github.com/sheridar/ggspruce/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sheridar/ggspruce/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

ggspruce provides functions that make automatic adjustments to ggplot2
Expand Down

0 comments on commit 529036d

Please sign in to comment.