davidhodge931 / ggblanket

Simplify ggplot2 visualisation
https://davidhodge931.github.io/ggblanket/
Other
156 stars 8 forks source link

set_blanket: non-named values in col scales does not work where there are named values in set col_palette_d #897

Closed davidhodge931 closed 4 months ago

davidhodge931 commented 4 months ago
library(ggblanket)
library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(palmerpenguins)

named_palette <- c(
  "blah" = "green",
  "Adelie" = "red",
  "Chinstrap" = "blue",
  "Gentoo" = "orange"
) 

set_blanket(col_palette_d = named_palette)

#ideally this would work
penguins |>
  gg_point(
    x = sex, 
    y = flipper_length_mm, 
    col = island, )
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's colour and fill values.
#> No shared levels found between `names(values)` of the manual scale and the
#> data's colour and fill values.
#> No shared levels found between `names(values)` of the manual scale and the
#> data's colour and fill values.
#> No shared levels found between `names(values)` of the manual scale and the
#> data's colour and fill values.
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).


#but can just do this
#ideally this would work
set_blanket()

penguins |>
  gg_point(
    x = sex, 
    y = flipper_length_mm, 
    col = island, )
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).

Created on 2024-06-07 with reprex v2.1.0

davidhodge931 commented 4 months ago

ggplot2 is the same