Giter VIP home page Giter VIP logo

palettes's Introduction

palettes

R-CMD-check Codecov test coverage CRAN status

palettes is an R package for working with colour vectors and colour palettes. There are three main goals to the palettes package, each described in a vignette:

  • To provide a new family of colour classes (palettes_colour and palettes_palette) that always print as hex codes with colour previews; vignette("palettes").

  • To provide a comprehensive library of methods for working with colour vectors and colour palettes, including methods for ggplot2, vignette("ggplot2"); gt, vignette("gt"); biscale, vignette("biscale"); and other colour packages, vignette("compatibility").

  • To make it easy for anyone to make their own colour palette package; vignette("creating-packages"). Colour palette packages made with palettes exist solely for the purpose of distributing colour palettes and get access to all the features of palettes for free.

Installation

Install palettes from CRAN with:

install.packages("palettes")

Install the development version from GitHub or R-universe with:

# Install from GitHub
# install.packages("remotes")
remotes::install_github("mccarthy-m-g/palettes")

# Install from R-universe
install.packages("palettes", repos = "https://mccarthy-m-g.r-universe.dev")

Install the WebAssembly version for use in WebR applications with:

# Install CRAN version from r-wasm
install.packages("palettes", repos = "https://repo.r-wasm.org")

# Install development version from R-universe
install.packages(
  "palettes",
  repos = c("https://mccarthy-m-g.r-universe.dev", "https://repo.r-wasm.org")
)

Usage

library(palettes)

Colours can be specified by name (as listed by grDevices::colours()):

pal_colour("red")

Or by hex code:

pal_colour("#FF0000")

Multiple colours can be specified at once as a character vector:

pal_colour(c("#a00e00", "#d04e00", "#f6c200", "#0086a8", "#132b69"))

Named colour palettes can be specified in the same way:

pal_palette(
  egypt = c("#dd5129", "#0f7ba2", "#43b284", "#fab255"),
  java  = c("#663171", "#cf3a36", "#ea7428", "#e2998a", "#0c7156")
)

Colours also print nicely in tibbles:

as_tibble(pal_colour(c("#dd5129", "#0f7ba2", "#43b284", "#fab255")))

Documentation

See at https://mccarthy-m-g.github.io/palettes/ and also in the installed package: help(package = "palettes").

License

MIT © Michael McCarthy

palettes's People

Contributors

mccarthy-m-g avatar olivroy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

palettes's Issues

Add `create_` function

For developers to create a new palettes package with all the boilerplate set up.

Can probably wrap usethis::create_from_github() and hard code it to a template repository. Only catch is this would require an Internet connection.

Or I can try to build everything manually using the appropriate use_ functions. use_template() looks like it will fit the bill.

Release palettes 0.2.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • devtools::check_mac_release()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

What is the `pal_brewer` function?

Hi Michael,

I'm working through the code in the Creating a Colour Package vignette and you make use of a pal_brewer function. When I run the code, I get an error: could not find function "pal_brewer". I can't find the function anywhere in the palettes code base nor in any other R package. What am I missing?

Thanks!

New/Better Hex Sticker

{palettes} could use a better hex sticker! Open to contributions for this 😄

I made the current one using some lightly modified free to use vector graphics. It’s okay, but could be a lot better.

Add info text to `validate_colour()` error message

The info text would provide a hint on how to fix the error. Something like (as separate “i” bullets):

  • Is/Are your hexadecimal string/strings of the form “#rrggbb” or “#rrggbbaa”?
  • Is/Are your colour name/names included in grDevices::colors()?

It would be nice to make this context aware, so only the relevant hint shows up if invalid colours are specified in a single way, and both show up if there are both invalid hex strings and colour names.

Add ggplot2 scale_ functions

Some examples here:

https://meghan.rbind.io/blog/2022-10-11-creating-custom-color-palettes-with-ggplot2/

https://www.garrickadenbuie.com/blog/custom-discrete-color-scales-for-ggplot2/

https://drsimonj.svbtle.com/creating-corporate-colour-palettes-for-ggplot2

These can also be used as default options with:

options(
  ggplot2.discrete.colour = function(...) scale_colour_viridis_d(..., begin = 0.15, end = 0.85),
  ggplot2.discrete.fill = function(...) scale_fill_viridis_d(..., begin = 0.15, end = 0.85),
  ggplot2.continuous.colour = function(...) scale_colour_viridis_c(..., begin = 0.15, end = 0.85),
  ggplot2.continuous.fill = function(...) scale_fill_viridis_c(..., begin = 0.15, end = 0.85)
)

Pretty display of colours

This can be accomplished using the crayon package; however, this may be unnecessary given that RStudio 1.6 might support this natively rstudio/rstudio#5424.

Edit: RStudio support seems to be for the editor pane, not output, so maybe still worth implementing myself

Export lighten and darken functions?

I notice that the code base has functions for lightening/darkening colour palettes and vectors but these are not exported. Any reason why not? They would be nice to have!

Add compact `print_style` option

The skittle/smartie swatches for colour palettes in this paper look nice and it would be cool to have the option to print palettes in the console like on page 8, for users who might want a compact display.

It would be controlled with a new option (palettes.print_style?), and the implementation would basically just involve not printing the hex codes—only symbols—and restricting the number of colours to 10 per line before a line break.

The print styles could have the following names: “default” (the current style), “compact”. Or the default could just be NULL rather than an explicit value. Either way, using strings here would be a good idea rather than a boolean in case I want to add new print styles in the future.

Plotting colours and palettes

Add a ggpalette() function that takes a palette or color as input and returns a ggplot themed like a swatch as output. Something like: https://images.app.goo.gl/j9Vu9NRJuC5vvMHr7

Doing this would also require creating as.dataframe() methods for the palette and color classes.

As far as handling multiple colours, facets would probably work well

Pretty print colour names in colour vectors

Since colours in colour vectors can be named, it might be nice to also output those names when they’re there (maybe as a muted grey colour in parentheses next to the hex code?).

I would probably exclude this when printing in tibbles though, because the output would be too wide there.

Bivariate colour interpolation (`pal_ramp_bibariate()`)

New function for creating bivariate colour palettes that can be used with the biscale package. Main points of consideration are:

  • Should the function take 4 colours as arguments (one for each corner of the palette), or 3 colours as arguments (with the 4th being interpolated based on the x and y colours)?
  • Should the number of dimensions be infinite, or should they be restricted? (this is more a practical question based on how well I can program something that generalizes well to higher dimensions, or if I can only create something nice for smaller numbers of dimensions)

v0.2.0

These are issues or features that I am considering for v0.2.0. Some of these may be pushed back to later versions or not be included at all.

If you have suggestions, please create a new issue.

If you would like to contribute, please comment on the relevant issue.

Items

Fix asciicast output in README

Right now the output in the README only shows the colour symbol and hex code, but it doesn’t show the <palettes_colour[1]> class above that like it’s supposed to (e.g., it should look how the pal_palette() output looks).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.