Get the App
SLTechnology News&Howtos  ›  Development  › 

How to choose colors according to rainbow in R language

Shulou Source: shulou.com Published: 2022-06-01 07:26:04 09月18日 Update

This article introduces the relevant knowledge of "how to take color according to rainbow in R language". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

rainbow() to get rainbow swatches

rainbow(n, s = 1, v = 1, start = 0, end = max(1, n - 1)/n, alpha = 1)

For example, 10 colors are obtained based on rainbow color gradient, which are sequentially refined by red, yellow, green, cyan, green, blue, magenta, etc.:

> rainbow(10) [1] "#FF0000FF" "#FF9900FF" "#CCFF00FF" "#33FF00FF" "#00FF66FF" "#00FFFFFF" "#0066FFFF" [8] "#3300FFFF" "#CC00FFFF" "#FF0099FF"

The corresponding colors appear as follows (draw ten incremental columns and fill them with the corresponding colors):

> barplot(1:10,col=rainbow(10))

How do I get a portion of the rainbow ribbon instead of going from red to the end position? It can be set based on the parameters start and end:

With rainbow, the parameters start and end can be used to specify particular subranges of hues. The following values can be used when generating such a subrange: red = 0, yellow = 1/6, green = 2/6, cyan = 3/6, blue = 4/6 and magenta = 5/6.

For example, color from red to blue:

> rainbow(10,start = 0,end=4/6) [1] "#FF0000FF" "#FF7100FF" "#FFE300FF" "#AAFF00FF" "#39FF00FF" "#00FF39FF" "#00FFAAFF" [8] "#00E3FFFF" "#0071FFFF" "#0000FFFF"> barplot(1:10,col=rainbow(10,start=0,end=4/6))

Start=1/6, end=5/6

> barplot(1:10,col=rainbow(10,start=1/6,end=5/6))"How to get color according to rainbow in R language" is introduced here. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Color rainbow language content more knowledge red practical learned next location parameters dilemma reality situation articles pillars cases ribbons websites Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Microsoft MySQL MariaDB