"Ggplot2: Data analysis and graphic art" notes

Source: Internet
Author: User

1th. Introduction to the syntax of the 1.3 graphic 2nd Chapter starting from Qplot 1, basic usage: Qplot (x,y,data) x is the horizontal axis of the argument, y is the vertical of the dependent variable, and data is the frame
2. Graphical parameter colour=i ("Red"), shape,size=i (2), Alpha=i (1/20)colour is the (outer box) color, fill is the filled color,shape is the point, suitable for describing categorical variables: shapes and colorssize is a point, suitable for describing continuous variables: size and colorAlpha is the transparency of the point, and 1/20 shows that 20 overlapping will become opaque and can be used to observe the dense area of the point

3, Geometric objects geom=c ("point", "smooth") are stacked sequentially, according to the data dimension can be divided into:
    • Two-dimensional variable relationship:
geom= "point": Plot scatter plot geom= "smooth": Fit a smooth curve, gray area is confidence interval, do not draw standard error se=faslegeom= "BoxPlot": Draw the box line beard diagram, summarize the distribution of a series of points geom= "Path" and geom= "line": Draw lines between data points, commonly used to explore the relationship between time and other variables, lines can only create left-to-right connections, and the path map may be in any direction
    • One-dimensional distribution: The collection object is determined by the variable type
      • Continuous variables:
geom= "histogram": Histogram (default) geom= "Freqpoly": Frequency polygon geom= "density": Density curve
      • Discrete variables:
geom= "Bar": Bar chart

3.1 Smoothing Curve geom= "Smooth" Specific ParametersThe default gray area is the confidence interval, and setting Se=false will not draw the standard error method parameter and select a different smoothing device:
    • method= "Loess", span=0. 1: Local regression method, the smoothness of the curve is controlled by span, memory consumption is O (n2), when n exceeds 1000 will be used other smoothing algorithm. N is the default option when it is smaller

    • Method= "Gam", Formula=y~s (x): MGCV package fits generalized additive model. Similar to the LM spline, but the order of the spline is obtained by data estimation. For Big Data (n>1000) use Y~s (x,bs= "CS")

    • Method= "LM": Linear model, the default is a line, can be Formula=y~poly (x,2) to fit two times polynomial, can also load splines package using spline Formula=y~ns (x,2), the second parameter is free, the greater the value, The greater the fluctuation of the curve

    • Method= "RLM": Mass package, similar to LM, but with a more robust fitting algorithm that makes the outliers less sensitive

3.2 box plots and perturbation point graphs: study the variation of continuous variables with categorical variables
  • Span style= "FONT-SIZE:15PX; line-height:1.6; " >geom= "jitter":
  • geom= "BoxPlot": box-line beard diagram,

3.3 Histogram and density graphs: shows the distribution of a single variable (continuous variable)
  • General drawing
geom= "Histogram" histogram, Binwidth set the group distance (the group is large to reflect the overall characteristics), break can display the specified shard position
geom= "Density": density graph, adjust controls the smoothness of the curve (the more smooth the Adjust curve)
  • increase Categorical variable control
Parameter colour or fill depending on the set categorical variable, the geometry is automatically split and a number of density graphs or histograms are plotted
3.4 Bar plots geom= "Bar" ( discrete variable)
  • Normal Bar chart
  • Increase continuous variable Weight: weight

3.5 Line and path graphs in time series
  • Geom= "line": Lines chart, sort by x (General horizontal axis is time), connect from left to right
  • geom= "path": Path graph, any original sequential connection (point order reflects time): Colour parameter set time to reflect

Group sets multiple sequence entities and maps to a diagram (4.5.3 section)

4, Facet: Facets split the graphic into multiple panes (7.2 sections) facets=row.var.name~.: Single Row multiple rowsfacets=Row. Var.name~col. Var.name: Multi-row multi-column“.. Density. " --new syntax for mapping density rather than frequency to y-axis
5. Other parameters main--title xlab,ylab--horizontal axis title. such as Ylab=expression (Frac (y,x)) =y/xxlim,ylim--Horizontal axis value range, such as C (. 2,1)log--log= "XY" or log= "X" to set a coordinate to take the logarithm
The 9th Chapter Data Operation 9.1 Plyr Package Introduction
    • Grouping variables: the data in a picture is divided into several parts.
    • Facet variables: used to divide the data into parts, each part drawn in a small picture.
Ddply (. Data,.variable,.fun)--Apply an action function to a separate subset for multiple subsets
    • Subset ()--used to take a subset of the data
ddply (Diamonds,. ( color), Subset,order (carat) <=2) #选取各个颜色里最小的2颗钻石
    • Transform ()--For Data transformation
ddply (Diamonds,. ( color), Transform,price=scale (price) #每个颜色 The prices of diamonds in the group are standardized
    • colwise ()--Convert a function of a processing vector into a data frame for each column
Colwise (func) func (<data.frame>) or Colwise (func) (<dataframe>)
      • Numcolwise ()--column operations on numeric types only
      • catcolwise () --only column operations on classification types
9.2 "Wide data" becomes "Long data" melt ()--the variable is no longer placed on each column, but in a column, each of which occupies several rows. Reshape2 Bag
Data
is a variant of the metadata id.vars still placed on the column, which is usually discrete, like a primary key in a database measure.vars a variable that needs to be placed in the same column, different variables are placed in the same column and grouped by variable name.

    • Multiple time series diagrams
Draw 2 time series on a picture:
1, draw two variables on two different layers
2, the data into a "Long data", and then according to the variable variable distinction
Analysis: Because two time series values differ too much, often cause one of the sequence values to approach a straight line
Improved method:
1, adjust the value to the same range: Do the very poor regularization transformation
2, using the free scale of the
facet
qplot (date,value,data=emp,geom= "line") +facet_grid (V Ariable~.,scale= "free_y")
    • Parallel Coordinate chart
Each sample draws a curve (need to ensure that the sample value is comparable), the row name RowName as a grouping variable, combined with the big Data mapping method (Transparencyand theclustering)
The main idea of the 9.3 Ggplot () method is to make the data deformation and graphic presentation as separate as possible, without having to confine the drawing to certain special functions. Ggplot is responsible for drawing, fortify () is responsible for data deformation ggplot is a generic function that provides only the tools needed for drawing.
    • Linear model


    • To write your own method
Other: 4th Chapter:1. Graphic attribute mapping:AES (X=X,Y=Y,COLOUR=Z) Graphic property parameters
2. Statistical transformation
3. Position adjustment
4. Integration





From for notes (Wiz)

"Ggplot2: Data analysis and graphic art" notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.