# Week 1

Get Started. It's Free
Week 1 by

## 1. Rules of analytical graphics

### 1.1. Show comparisons

1.1.1. Compared to What?

1.1.2. Evidence for hypothesis is always relative to something

### 1.2. Show caruality, mechanism, explanation, systematic structure

1.2.1. What is your casual framework?

1.2.2. You must have an idea how things work, why there should be difference

### 1.3. Show multivariate data

1.3.1. More than 2 variables

1.3.2. Show as much variables as possible

1.3.3. Be reasonable: segment

1.3.4. Another idea: confidence intervals

### 1.4. Integration of evidence

1.4.1. Integrate words, numbers, images, diagrams

1.4.2. Don't let the tool drive the analysis

### 1.6. Content is king

1.6.1. Make story, content of your graphs

## 2. Explaratory graphs

### 2.1. Why

2.1.1. Understand data

2.1.2. Find patterns

2.1.3. Suggest modeling strategies

2.1.4. Debug analysis

2.1.5. Communicate analysis

### 2.2. Characteristics

2.2.1. Meda quickly

2.2.2. Large numbers

2.2.3. Personal understanding only

2.2.4. Very raw: no axis, labels

### 2.3. How

2.3.1. summary()

2.3.2. boxplot

2.3.3. histogram

2.3.3.1. with rug() - shows exact points

2.3.3.1.1. это density plot

2.3.3.2. abline - to draw important lines, thresholds

2.3.3.2.1. abline(v = 12, lwd = 2) - просто линия на точке 12

2.3.3.2.2. abline(v = median(pollution\$pm25)) - линия на медиане

2.3.4. barplot

2.3.4.1. for categorical variables

2.3.5. two dimensional summaries

2.3.5.1. multiple histograms

2.3.5.1.1. just use par чтобы разбить области

2.3.5.2. multiple boxplots

2.3.5.2.1. boxplot(pm25 ~ region, data = polution)

2.3.5.3. scatterpolts

2.3.5.3.1. plot()

2.3.5.3.2. опять же можно сделать 2 через par

2.3.5.3.3. par(mfrow = c(1,2), mar = c(5, 4, 2, 1))

2.3.5.4. smooth scaterplots

2.3.6. > than 2 dimensional structures

## 3. Plotting systems in R

### 3.1. base plotting system

3.1.1. artist palette model

3.1.1.1. blank in the beginning

3.1.1.2. use annotations functions to add/modify (text, lines, points, axis)

3.1.1.3. so you create a plot and then annotate the plot

3.1.1.4. drawbacks

3.1.1.4.1. Had to contol everything

### 3.2. Lattice system

3.2.1. Plots are are created at once by call of one function

3.2.2. lattice package

3.2.2.1. xyplot, bwplot

3.2.3. Do a lot of stuff automatically, because functions are smart

3.2.4. Good for putting many many plots on a screen

3.2.5. drawbacks

3.2.5.1. functions are huge

3.2.5.2. cannot add anything after function is called

3.2.5.3. wierd and requires a lot of preparations

### 3.3. ggplot2

3.3.1. Grammar graphics

3.3.1.1. Creates a language for drawing a plot

3.3.2. Can be used to incrementaly build graph

3.3.3. Deal with spacings

3.3.4. Mixes elements of Base and Lattice

### 3.4. Cannot be interchangeable

3.4.1. Choose system and stick to it

## 4. Base plotting system in R

### 4.1. structure

4.1.1. graphics package

4.1.2. grDevices package

### 4.2. Considetions to makr

4.2.1. Where: on screen or file

4.2.2. How will be used

4.2.3. How many data to plot

4.2.4. Do you need to resize dynamically?

### 4.3. 2 phases of creation

4.3.1. Initialize a new plot

4.3.1.1. plot

4.3.1.2. hist

4.3.1.3. boxplot

4.3.2. Annotate

### 4.4. Key parameters

4.4.1. pch - plotting symbol

4.4.2. lty - line type

4.4.3. lwd - line width

4.4.4. col - color

4.4.4.1. number

4.4.4.2. string

4.4.4.3. hex code

4.4.5. xlab

4.4.6. ylab

4.4.7. par() parameters

4.4.7.1. las - orientation of axis labels on plot

4.4.7.2. bg - background color

4.4.7.3. mar - margin size

4.4.7.3.1. 4 numbers starting from bottom, clock-wise

4.4.7.4. oma - outer margin size

4.4.7.5. mfrow - number of plots per row, column and plots are filled row-wise

4.4.7.6. mfcol - number of plots per row, column and plots are filled column-wise

### 4.5. Key functions

4.5.1. plot

4.5.2. lines

4.5.2.1. Often used with lm()

4.5.3. points

4.5.3.1. useful with subset to draw points in different colors

4.5.3.2. with(subset(data, Month == 5), color = )

4.5.4. text

4.5.5. title

4.5.6. mtext

4.5.6.1. place text to margin

4.5.6.2. Полезно, например если хочется назвать группу графиков.

4.5.7. axis

4.5.8. legend

## 5. Graphic devices

### 5.2. File

5.2.1. Vector formats

5.2.1.1. PDF file

5.2.1.1.1. Useful, when not too much points

5.2.1.2. SVG

5.2.1.3. win.metafile

5.2.1.4. postscript

5.2.2. Bitmap formats

5.2.2.1. png

5.2.2.2. jpeg

5.2.2.3. tiff

5.2.2.4. bmp

### 5.4. Common procedure

5.4.1. Open graphic device (if not screen)

5.4.2. plot

5.4.3. Annotate

5.4.4. dev.off()

### 5.5. Can open multiple graphic devices

5.5.1. Current device - dev.cur()

5.5.2. dev.set(<integer>), where every open is assigned integer > 2

### 5.6. Copy plots

5.6.1. dev.copy

5.6.2. dev.copy2pdf

5.6.3. May appear not exact the same as on screen