Creating Your Own Color Palette for Data Visualization: Part 2 | by Abhinav Malasi | Feb, 2021


The RGB values are specified as (crimson, inexperienced, blue) and the depth of every colour varies between (0,255). So, for a crimson colour RGB price is (255,0,0), for inexperienced colour it’s (0,255,0) and for blue colour it’s (0,0,255). Sometimes, the depth values are outlined within the vary of (0,1). The conversion is just dividing the RGB values by 255. So, for the crimson, inexperienced, and blue colours the RGB values within the (0,1) scale shall be:

The RGB colour combos will also be additional tuned as:

Shades of colour will also be generated by mixing them with black colour. Black is (0,0,0) in RGB structure.

The tint of colour is generated in a similar fashion because the sun shades however by mixing the colour with white. White is (1,1,1) in RGB structure.

Tones then again are generated by mixing the colour with grey. In RGB structure the grey colour is (0.5,0.5,0.5).

If the RGB colour structure is transformed to the cylindrical coordinate gadget then the HSL gadget originates. HSL stands for Hue, Saturation, and Luminance.

Hue (H) represents the perspective of the colour with the dominant power within the visual mild spectrum. The attitude varies between (0°,360°), and with regards to colour, it begins with crimson and shifts to yellow to inexperienced to cyan to blue to magenta and again to crimson.

Let us now take a look at the mathematics at the back of changing the RGB values to the HSL colour gadget. There are three variables R, G, and B so there are 6 conceivable techniques to organize RGB with out repeating any colour two times or three times. The conceivable results are and the formulation related to them for conversion to HSL:

The saturation (S) of colour has a tendency to inform its brightness. It is measured on a scale of (0,1). The Zero price represents the absence of colour and 1 represents the colour at its complete brightness. To calculate the price of saturation, the utmost and minimal values of RGB are required. This way the max/min price is calculated evaluating the values of R, G, and B.

Luminance (L) then again defines the depth, luminosity, or brightness of the colour on a scale of (0,1) the place 1 represents the brilliant area and zero the darkish area or the natural colour.

The chroma (C) then again is the purest type of colour with none blendings of both white, black, or grey colours. It may be measured between the scales of (0,1).

Now we have now all of the definitions we want to learn about colours, let’s put all this information to construct our code.

There are 2 techniques we will convert RGB to HSL. The first manner is to make use of the formulation outlined within the earlier segment. The 2d and the shorter course is to make use of the rgb2hsl() serve as shape the plotwidgets package deal of R. I can give you the code for the primary manner and the second one manner is left for the readers to discover.

By opting for a selected colour the saturation and luminance will also be various as proven within the under symbol.

We know the way to transform RGB to HSL, let’s plot and generate a colour wheel for HSL parameters.

For plotting HCL, the place C is chroma, one can use hcl() serve as as a substitute of hsv() within the above code.

For this phase, we will be able to forget about the math for changing HSL to RGB and will immediately use the hsl2rgb() serve as from the plotwidgets package deal of R. The enter argument for the hsl2rgb() serve as is a matrix of three rows. The three rows constitute the HSL values the place H varies between (0°,360°). And the ensuing output may be a matrix of three rows known as RGB.

Here are few pointers for environment friendly plotting in R the usage of ggplot2 package deal.


Please enter your comment!
Please enter your name here