Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Back in September 2022 I submitted {PrettyCols}, an R package containing aesthetically pleasing colour palettes, to CRAN. If you missed it, you can read the blog post introducing the package!
After a few months, it was time for an update and this blog post will give you a brief overview of some of the new features and palettes! You can install {PrettyCols} using:
install.packages("PrettyCols")
You can also install the development version from GitHub using:
remotes::install_github("nrennie/PrettyCols")
More palettes! < svg class="anchor-symbol" aria-hidden="true" height="26" width="26" viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg"> < path d="M0 0h24v24H0z" fill="currentColor"> < path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z">
The new release contains twelve additional palettes, including two new sequential palettes (Yellows
and Reds
), two new diverging palettes (PurpleYellows
and RedBlues
), and eight new qualitative palettes. You can see the complete list of available palettes by running view_all_palettes()
:
or browsing the package vignette on available palettes.
Colourblind friendly palettes < svg class="anchor-symbol" aria-hidden="true" height="26" width="26" viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg"> < path d="M0 0h24v24H0z" fill="currentColor"> < path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z">
PrettyCols::view_all_palettes(colourblind_friendly = TRUE)
You can combine filtering by palette types with filtering by colourblind friendliness, for example to view only colourblind friendly diverging palettes:
PrettyCols::view_all_palettes(type = "div", colourblind_friendly = TRUE)
The view_all_palettes()
function now also supports filtering by multiple types, e.g. to view all sequential and diverging palettes:
PrettyCols::view_all_palettes(type = c("seq", "div"))
The colourblind-friendliness has been checked using colorblindcheck::palette_check()
, and a judgement made based on the number of distinct colour pairs with deuteranopia, protanopia, tritanopia in comparison to full colour vision. This judgement may not always be correct, and if you think a colour palette has been listed as colourblind friendly in error, please raise a
GitHub issue and I’ll re-classify the palette.
Python support < svg class="anchor-symbol" aria-hidden="true" height="26" width="26" viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg"> < path d="M0 0h24v24H0z" fill="currentColor"> < path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z">
This colour palette package was originally developed for use with R, particularly with {ggplot2}. However, many people make charts and generative art with Python instead. So, now you can use PrettyCols with Python. The Python code is adapted from the {MetBrewer} package from Blake Robert Mills which also provides support for R and Python.
You can install from GitHub and read more about how to use these palettes with Python in the Using with Python package vignette.
Here’s a small example of using the Bright
colour palette with matplotlib
to make a bar chart:
import prettycols import matplotlib.pyplot as plt colors = pretty_cols(name="Bright", n=3, palette_type="discrete") x = ['A', 'B', 'C'] value = [1, 2, 3] plt.bar(x, value, color=colors) plt.show()
To end this post, here’s another couple of examples of these palettes being used for generative art!
aRt::puzzles(n = 200, num_groups = 30, col_palette = PrettyCols::prettycols("Lively"), bg_col = "white", s = 1234) aRt::stacked(n_x = 4, n_y = 4, col_palette = PrettyCols::prettycols("Lucent"), shadow_intensity = 0.1, sunangle = 315, s = 124)
There are plans for a few more updates in the future including even more palettes, and support for diverging colour scales in {ggplot2} which allows you to specify a midpoint for the scale. If you find that something in {PrettyCols} isn’t working, or if you’ve got an idea for more features, please raise a GitHub issue!
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.