Day 16 – little helper statworx_palette
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
We at STATWORX work a lot with R and we often use the same little helper functions within our projects. These functions ease our daily work life by reducing repetitive code parts or by creating overviews of our projects. At first, there was no plan to make a package, but soon I realised, that it will be much easier to share and improve those functions, if they are within a package. Up till the 24th December I will present one function each day from helfRlein
. So, on the 16th day of Christmas my true love gave to me…
What can it do?
This little helper is an addition to yesterday's sci_palette()
. We picked colors 1, 2, 3, 5 and 10 to create a flexible color palette. If you need 100 different colors – say no more!
How to use it?
In contrast to sci_palette()
the return value is a character vector. For example if you want 16 colors:
statworx_palette(16) [1] "#013848" "#004C63" "#00617E" "#00759A" "#0087AB" "#008F9C" "#00978E" "#009F7F" [9] "#219E68" "#659448" "#A98B28" "#ED8208" "#F36F0F" "#E45A23" "#D54437" "#C62F4B"
If we now plot those colors, we get a nice rainbow like color gradient.
library(ggplot2) ggplot(plot_data, aes(x = X, y = Y)) + geom_point(pch = 16, size = 15, color = statworx_palette(16)) + theme_minimal()
An additional feature is the reorder
parameter, which samples the color's order so that neighbours might be a bit more distinguishable. You can also use other colors from sci_palette()
with basecolors
.
ggplot(plot_data, aes(x = X, y = Y)) + geom_point(pch = 16, size = 15, color = statworx_palette(16, basecolors = c(4,8,10))) + theme_minimal()
Overview
To see all the other functions you can either check out our GitHub or you can read about them here.
Have a merry advent season!
STATWORX
is a consulting company for data science, statistics, machine learning and artificial intelligence located in Frankfurt, Zurich and Vienna. Sign up for our NEWSLETTER and receive reads and treats from the world of data science and AI.
Der Beitrag Day 16 – little helper statworx_palette erschien zuerst auf STATWORX.
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.