introtor.review

Welcome to R.


Work Flow

Reproduceable Analysis: 可重现分析

How to organize your project?(just some suggestions)

  • Save the original files others sent to you
  • Name those original file folders by time
  • Format data in Excel
    A small trick: View -> Freeze Panes
    Save Excel files as Excel Workbook, otherwise the format you made won’t be kept.
  • Don’t edit text files directly
  • Analysis Files

Today’s Tips:

  • There’s a programming language in Excel called VBA
  • R script: like a huge R code chunk. The outputs will be shown in Console window and the graphs will be shown in Plots windows on the right of R Studio.
  • π in R is pi.

Review of Graphs

Pie Chart

To show the relative proportions.

One-dimentional Graph

Strip Chart

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
stripchart( rivers,
main = " Stripchart",
ylim = c(0, 2),
xlab = "River Length(miles)",
method = "jitter",
jitter = 0.5,
col = "navy",
pch = 19,
cex = 2
)

sample.mean <- mean( rivers )

segments( sample.mean, 0.2,
sample.mean, 1.8,
lwd = 3, lty = 2 )

text( sample.mean, 1.9, "Sample Mean" )

Box Plot

1
2
3
4
5
boxplot( rivers,
main = "Box Plot",
horizontal = TRUE,
xlab = "River Length(miles)",
col = "gold")

Histogram

1
2
3
4
5
6
7
hist( rivers,
main = "Histogram",
xlab = "River Length(miles)",
ylab = "Density",
probability = TRUE,
breaks = 30,
col = "blue")

Stratified Graphs

use “~”.

Two-dimentional Graphs

Scatter Plot

1
2
3
4
5
6
7
8
9
10
11
plot( iris$Petal.Width ~ iris$Petal.Length,
main = "Scatter Plot",
xlab = "Petal Width (cm)",
ylab = "Petal Length (cm)",
pch = 24,
cex = 1.5,
bg = "aquamarine2")

regression.model <- lm( iris$Petal.Width ~ iris$Petal.Length )

abline( regression.model, col = "darkblue", lty = 4, lwd = 3 )