In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of "how to set colors and swatches in R language". The editor shows you the operation process through actual cases, which is simple, fast and practical. I hope this article "how to set colors and swatches in R language" can help you solve the problem.
Color is often the least considered factor when visualizing data. Indeed, in a graph, the selection of data and the determination of chart types are the most important and need to be determined. However, the appropriate selection of color can not only make the readers of the data graph pleasing to the eye, but also contribute to the presentation of the data relationship in the graph, making the whole chart more persuasive.
1. Default colors in R language
In R, you can customize the color by defining the col parameter. There are four ways to set it, which are equivalent:
Number: (for example, 1 represents the first color of current palette, 2 represents the second color of current palette, etc.)
Color names: (such as "red", "blue"), you can use colors () to get a list of all color names
RGB: the return value rgb (1,0,0) obtained by using the rgb () function
Hexadecimal color code: # FF0000
Barplot (1:4, col = c (2, "red", rgb (1, 0, 0), "# FF0000"))
People can't help but ask, what color do different numbers represent?
Through the palette () function, you can see that under the current palette, the first color is black and the second color is red. There are 8 colors in this palette, and when the number of colors used is greater than 8, it will start from scratch.
Palette () # # [1] "black", "red", "green3", "blue", "cyan", "magenta", "yellow" # # [8] "gray"
Palettes can of course be changed, such as using the rainbow palette in the system. At this point, the second place is not red.
Palette (rainbow (12)) barplot (1:4, col = c (2, "red", rgb (1,0,0), "# FF0000"))
You can get the default palette by setting palette to "default" again.
Palette ("default") 2.R preset the color swatch of the color system
In fact, in the R language color system, there are two types of color systems, one is the preset color palette, through the color palette, you can get any number of color combinations.
There are five default palettes for the R language:
Rainbowheat.colorsterrain.colorstopo.colorscm.colors
These five color palettes are like a large dye vat, arranged with countless color combinations. Color selection is also very simple, that is, you can use the preset color disk name + color data:
Rainbow (10) [1] "# FF0000FF", "# FF9900FF", "# CCFF00FF", "# 33FF00FF", "# 00FF66FF", "# 00FFFFFF" [7], # 0066FFFF "# 3300FFFF", "# CC00FFFF"# FF0099FF"
Since the above is a group of 10 colors obtained by name + quantity, we can also view the specific color effect through the show_col function in the scales package:
Library (scales) show_col (rainbow (10), labels=T) # labels controls whether color value information in HEX format is displayed.
Next, I use a layout matrix to display all five color plates:
Par (mfrow=c (1, 5), mar=c (0.5, 0.5), xaxs= "I", yaxs= "I") n
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.