Closed wetlandscapes closed 6 years ago
Hello jmerc13!
Thanks for your interest, it appears that you forgot to unquote when passing pack and pal into paletteer_d
.
library(tidyverse)
library(paletteer)
library(pals)
color_plot_d <- function(package, name, n){
palette <- paletteer::palettes_d_names %>%
as_data_frame %>%
dplyr::filter(package == package, palette == name)
pack <- palette$package
pal <- palette$palette
n <- palette$length
pals::pal.bands(
paletteer_d(!!pack, !!pal),
main = paste(pack, pal, sep = ": ")
)
}
color_plot_d(package = "awtools", name = "a_palette")
If you want to see all the palettes in this package I have compiled a visual list here: https://github.com/EmilHvitfeldt/r-color-palettes which also have them sorted by style.
Holy crap, you just blew my mind! I've never seen that syntax before. Thanks for letting me know and responding so quickly!
And your r-color-palettes page is super useful.
Cheers!
you are very welcome!
further look reveals some redundency in your function. Similar functionality comes with
library(paletteer)
library(pals)
color_plot_d <- function(package, name, n){
pals::pal.bands(
paletteer_d(!!package, !!name, n = n),
main = paste(package, name, sep = ": ")
)
}
color_plot_d(package = "awtools", name = "a_palette")
Hi, Really cool package. I appreciate what you've done here.
I'm running into a bit of trouble passing the names of packages and palettes to
paletteer_d()
, however.Here's my scenario: I wanted to create a function for your package that would allow me to visualize the colors from a specific package, palette, etc. so that i could rapidly review the palettes, and see which one might best fit my needs, without having to manually entire each name. Focusing on just the fixed width discrete palettes, I made a function:
However, I get this error:
It seems that this behavior is the results of the follwing two lines of code in
paletteer_d()
:It appears that I can only pass quoted or unquoted versions of the name, but not object representations of the name. I'd hoped to provide a solution to this problem, but this is a level of R I'm not yet familiar with.
Instead, my work around was to simply create a duplicate of the
paletteer_d()
function, but to comment out the two lines causing me problems. However, this means that if one passes an unquoted representation of a package or palette (e.g.awtools
) then a different error occurs.Not sure if this matters to you, but just thought I'd pass the information along, in case it was useful.
Again, I appreciate your effort on this package. Keep up the great work!