First, Introduction:
Ggplot2 is a very popular drawing package in the R language and is very friendly to use. The realization of Ggplot2 is due to the Leland Wilkinson in his book "TheGrammar of the graphics" proposed a set of graphic grammar, the graphic elements into the composition can be freely combined, Hadley Wickham This set of ideas in R . Hadley Wickham has this special Ggplot2 book------ggplot2: Data analysis and Graphic arts, interested can be read.
Here is an introductory ppt------30 minutes to learn ggplot2.pdf, everyone can view;
Ii. Preparatory work:
1) Install r Software (required):http://www.r-project.org, first select the image, then download;
2) Install Rstudio (optional):Http://www.rstudio.com/products/rstudio/,RStudio is a wide application of the IDE, powerful and friendly, recommended installation;
3) Load Ggplot2 (required): Open R, enter on the command line: Install.packages ("Ggplot2"), will let you choose to automatically install after mirroring, in the script to call the package, you need to load the package, enter the library (GGPLOT2) can be;
Three, Ggplot2 basic concept:
1) Mapping:
The variables in the data are mapped to the graphic properties, such as the following data (table I), the TRT column is mapped to a color (table II), the display effect is shown;
The command is:
data = Data.frame (Length=c (2,1,4,5), Width=c (3,2,5,6), Trt=c ('a','a ','b','b'= ggplot (data, AES (length , width, col=+ geom_point ()
Table I:
| Length |
Width |
Trt |
| 2 |
3 |
A |
| 1 |
2 |
A |
| 4 |
5 |
B |
| 5 |
6 |
B |
Table II:
| length |
width |
Colour |
| 2 |
3 |
A |
| 1 |
2 |
A |
| 4 |
5 |
B |
| 5 |
6 |
B |
Figure One:
Figure One:
2) Scaling (scale):
The scale is responsible for the mapping after the graphical display, specifically the legend and the coordinate scale, that is, the corresponding specific values after mapping, such as table two data, the actual corresponding scale such as:
| length |
width |
Colour |
| 25 |
20 |
Red |
| 0 |
0 |
Red |
| 75 |
60 |
Blue |
| 100 |
80 |
Blue |
R Paint Package Ggplot2 Introduction