Before introducing ggplot2, let me introduce the author Hadley Wickham. Hadley (Faculty, Department of Statistics, Rice University)
I got my doctor's degree from Iowa State University, a famous statistical college, and my doctoral thesis is Practical Tools for.
Exploratory data and models are about data visualization and exploratory data analysis, and are currently accessories of Rice University.
Assistant professor and R's famous IDE.
The chief scientist of RStudio. Hadley enjoys a high reputation among R language users. The basic version of R is actually not very easy to use, but Hadley's series of excellent works have been greatly improved.
R language. At the R language conference held in Beijing in May this year, many people rushed to take photos with Hadley, which shows that Hadley's charm and fame are extraordinary. Hadley developed a package.
A version will be developed first. If it is not good enough, it will be upgraded, and then a new version will be issued. After the name becomes the old name, the number 2 will be added. So we reinvented 2 and.
ggplot2 .
Ggplot2 is based on the theory put forward by Leland Wilkinson in Grammar of Graphics, and is named Ggplot after adding the acronym to it. According to the view of graphic grammar, statistical chart is the mapping of color, shape or size from data to geometric objects such as points, lines or squares, which may also include statistical transformation of data (such as finding mean or variance). Finally, the graphics we need are drawn in a coordinate system. There may be facets in the picture,
Is to generate charts of different subsets of data. The process of drawing with ggplot2 is the process of selecting suitable geometric objects, graphic attributes and statistical transformation to fully expose the information contained in the data.
It takes some time to get started with Ggplot2, but when you master the grammar of graphics in ggplot2, I believe you will feel the elegance of this grammar.
In the next part, I assume that readers have a basic understanding of R language, so I won't introduce basic concepts such as DataFrame.
Installing ggplot2 is no different from installing other R packages. Just run the phrase install. packages(“gg plot 2 ") in the console of R. If you use RStudio, you can also use the mouse to install it in the package list.
Let's first introduce some basic concepts in ggplot2, and the parentheses correspond to the parameter names that need to be used when assigning values to this attribute in ggplot2.
Graphic properties (aes) horizontal and vertical coordinates, point size, color, fill color, etc.
Geometric objects (geom_) need to be represented on some geometric objects before they can be seen by us. These objects with graphic properties can be points, lines or bars.
When we need to show some statistical characteristics of a variable, we need to carry out statistical transformation, such as finding the mean and variance.