Closed davidhodge931 closed 2 months ago
Maybe add alpha_recursive = NULL
and think about the rest for a while
Doesn't work that well for setting col_palette_colour, as it would affect geoms with no fill
Also, doesn't work that well for lighten as changes the colour of the main thing you see..
Maybe just add alpha_recursive and mull on the rest of it
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.4.1
library(ggblanket)
library(palmerpenguins)
library(colorspace)
set_blanket(
alpha_recursive = 1,
)
penguins |>
gg_density(
x = flipper_length_mm,
colour = darken(blue, 0.33),
)
#> Warning: Removed 2 rows containing non-finite outside the scale range
#> (`stat_density()`).
penguins |>
gg_density(
x = flipper_length_mm,
col = species,
) +
scale_colour_manual(values = darken(jumble, 0.33))
#> Scale for colour is already present.
#> Adding another scale for colour, which will replace the existing scale.
#> Scale for colour is already present.
#> Adding another scale for colour, which will replace the existing scale.
#> Warning: Removed 2 rows containing non-finite outside the scale range
#> (`stat_density()`).
Created on 2024-07-23 with reprex v2.1.0
Doesn't work so well as using alpha, as you need different defaults for geoms with only colour, compared to those with colour/fill
penguins |>
tidyr::drop_na(sex) |>
group_by(sex, species) |>
summarise(across(flipper_length_mm, \(x) mean(x, na.rm = TRUE))) |>
gg_col(
x = flipper_length_mm,
y = species,
col = sex,
position = position_dodge(preserve = "single"),
width = 0.75,
col_labels = \(x) str_sub(x, 1, 1), # doesn't work
col_breaks = "female", # doesn't work
) +
scale_colour_manual(values = darken(jumble, 0.33))
Better solution: col_palette could accept a list of 2 elements for the colour and fill colours
col_palette = list(jumble, lighten(jumble, 0.2))
aes_darken_colour <- function(amount = 0.1, ...) {
aes(colour = ggplot2::after_scale(colorspace::darken(fill, amount = amount)))
}
aes_lighten_colour <- function() {
aes(colour = ggplot2::after_scale(colorspace::darken(fill, 0.2)))
}
penguins |>
gg_bar(
y = species,
col = island,
mapping = aes_darken_colour(amount = 0.5),
)
library(ggblanket)
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.4.1
library(palmerpenguins)
library(colorspace)
set_blanket(
alpha_recursive = 1,
colour = teal,
col_palette_d = c('red', "blue", "grey"),
)
aes_darken_colour <- function(...) {
ggplot2::aes(colour = ggplot2::after_scale(colorspace::darken(fill, ...)))
}
aes_lighten_colour <- function(...) {
ggplot2::aes(colour = ggplot2::after_scale(colorspace::darken(fill, ...)))
}
penguins |>
gg_bar(
y = species,
colour = colorspace::darken(teal),
)
penguins |>
gg_bar(
y = species,
col = island,
mapping = aes_darken_colour(),
)
#> Scale for colour is already present.
#> Adding another scale for colour, which will replace the existing scale.
penguins |>
gg_bar(
y = species,
colour = colorspace::darken(teal, amount = 0.5),
)
penguins |>
gg_bar(
y = species,
col = island,
mapping = aes_darken_colour(amount = 0.5),
)
#> Scale for colour is already present.
#> Adding another scale for colour, which will replace the existing scale.
Created on 2024-07-23 with reprex v2.1.0
aes_colour_darken <- function(...) { ggplot2::aes(colour = ggplot2::after_scale(colorspace::darken(fill, ...))) }
aes_colour_lighten <- function(...) { ggplot2::aes(colour = ggplot2::after_scale(colorspace::darken(fill, ...))) }
aes_colour_contrast <- function(...) { ggplot2::aes(colour = ggplot2::after_scale(colorspace::darken(fill, ...))) }
library(ggblanket)
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.4.1
library(palmerpenguins)
library(colorspace)
set_blanket(
alpha_recursive = 1,
)
aes_colour_darken <- function(...) {
ggplot2::aes(colour = ggplot2::after_scale(colorspace::darken(.data$fill, ...)))
}
aes_colour_lighten <- function(...) {
ggplot2::aes(colour = ggplot2::after_scale(colorspace::lighten(.data$fill, ...)))
}
aes_fill_darken <- function(...) {
ggplot2::aes(fill = ggplot2::after_scale(colorspace::darken(.data$colour, ...)))
}
aes_fill_lighten <- function(...) {
ggplot2::aes(fill = ggplot2::after_scale(colorspace::lighten(.data$colour, ...)))
}
penguins |>
gg_bar(
y = species,
colour = darken(blue, amount = 0.2),
width = 0.75,
)
penguins |>
gg_bar(
y = species,
col = island,
mapping = aes_colour_darken(amount = 0.2),
width = 0.75,
)
#> Scale for colour is already present.
#> Adding another scale for colour, which will replace the existing scale.
Created on 2024-07-23 with reprex v2.1.0
In
gg_*
:col_palette_colour
col_palette_fill
In
set_blanket
,weave_geom_defaults
andweave_col_palette_*
:alpha_recursive = NULL
col_palette_colour_d
col_palette_fill_d
col_palette_na_colour_d
col_palette_na_fill_d
etc