In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.