What’s new in {PrettyCols} 1.0.1?
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!
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
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
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!
Show code
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.