In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about R language ggplot2 graphics common color matching methods are what, the editor feels very practical, so share with you to learn, I hope you can learn something after reading this article, say no more, follow the editor to have a look.
Examples show several commonly used ggplot color extraction methods, such as:
Distinguishing colors by strings
Color extraction by numbers
Take gradual discoloration
The color is selected by RColotBrewer scheme.
1. Construct dataset # Construct dataset df = data.frame (y=seq (1,20,2), z=seq (1000, 100,100), c=paste ("color", seq (1,10,1)) df
Running result:
two。 Install and load package install.packages ("ggplot2") # install package install.packages ("RColorBrewer") library (ggplot2) # load package library (RColorBrewer) 3. Ggplot (df, aes (x, y)) + geom_bar (stat= "identity")
Running result:
3.2 default Color
In ggplot2's graphics syntax, color is a graphic attribute, just like the position of x, the position of y, the size, and so on.
For geometric objects in a drawing, you can set the color by setting the value of the colour or fill parameter.
Generally speaking, the colour parameter controls the color of lines and polygon outlines, while the fill parameter controls the fill color of polygons.
If you need a variable (a column of the data box) to control the color of the geometric object, set the value of the colour or fi11 parameter to the column name of a column in the data.
Ggplot (df, aes (x, y, fill=c)) + geom_bar (stat= "identity") + labs (x = "x axis", y = "y axis", fill= "legend")
Running result:
3.3 Digital Color selection-positive sequence
The x variable is an incremental vector.
Ggplot (df, aes (x, y, fill=x)) + geom_bar (stat= "identity") + labs (x = "x axis", y = "y axis", fill= "legend")
Running result:
3.4 Digital Color selection-reverse order
The z variable is a decreasing vector.
Ggplot (df, aes (x, y, fill=z)) + geom_bar (stat= "identity") + labs (x = "x axis", y = "y axis", fill= "legend")
Running result:
3. 5 gradient: color 1-color 2 colors
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.