30
Lesson 1: R Basics

Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

Lesson 1: R Basics

Page 2: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

Make an R Project

This Lesson’s Goals

Read in and manipulate data

Make a figure and save to PDF

Create an R Markdown document

Commit to Git

Push to Bitbucket

Page 3: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

variable

levels of a variable

data frame

Page 4: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

There are lots of ways to dothe same thing in R

data_bl = data[data$group == “bilingual”,]

data_bl = subset(data, group == “bilingual”)

data_bl = data %>% filter(group == “bilingual”)

data frame datavariable grouptwo levels monolingual, bilingual

Page 5: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

dplyr

Page 6: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

new data frame

dplyr

data_bl = data %>% filter(group == “bilingual”)

Page 7: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

data_bl = data %>% filter(group == “bilingual”)

original data frame

new data frame

dplyr

Page 8: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

data_bl = data %>% filter(group == “bilingual”)

original data frame

new data frame

pipe

dplyr

Page 9: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

dplyr

data_bl = data %>% filter(group == “bilingual”)

Page 10: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

dplyr

data_bl = data %>% filter(group == “bilingual”)

Page 11: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

data_bl = data %>% filter(group == “bilingual”)

Page 12: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

= is used to assign (<- also used)

data_bl = data %>% filter(group == “bilingual”)

== is a marker of relationship (e.g. <, >)

Page 13: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

> dim(data)[1] 400 3

> dim(data_bl)[1] 200 3

Page 14: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

= is used to assign (<- also used)

data_bl = data %>% filter(group == “bilingual”) %>%

== is a marker of relationship (e.g. >, <)

Page 15: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

= is used to assign (<- also used)

data_bl = data %>% filter(group == “bilingual”) %>%

== is a marker of relationship (e.g. >, <)

Page 16: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

= is used to assign (<- also used)

data_bl = data %>% filter(group == “bilingual”) %>% filter(rt < 1100)

== is a marker of relationship (e.g. >, <)

Page 17: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

= is used to assign (<- also used)

data_bl = data %>% filter(group == “bilingual”) %>% filter(rt < 1100)

== is a marker of relationship (e.g. >, <)

Page 18: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

= is used to assign (<- also used)

data_bl = data %>% filter(group == “bilingual”) %>% filter(rt < 1100)

== is a marker of relationship (e.g. >, <)

Page 19: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

> dim(data)[1] 400 3

> dim(data_bl)[1] 153 3

Page 20: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

Page 21: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plot

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 22: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 23: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data frame

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 24: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data frameaesthetics

to plot

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 25: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data frameaesthetics

to plotvariable to set to x-coordinate

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 26: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data frameaesthetics

to plotvariable to set to x-coordinate

variable to set to y-coordinate

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 27: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data frameaesthetics

to plotvariable to set to x-coordinate

variable to set to y-coordinate

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 28: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data frameaesthetics

to plotvariable to set to x-coordinate

variable to set to y-coordinate

plot type

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 29: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

ggplot2

plotinitializes

plot

data frameaesthetics

to plotvariable to set to x-coordinate

variable to set to y-coordinate

plot typecall

plot

data.plot = ggplot(data, aes(x=group, y=rt)) + geom_boxplot()

data.plot

Page 30: Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project This Lesson’s Goals Read in and manipulate data Make a figure and save to PDF

900

950

1000

1050

1100

1150

bilingual monolingualgroup

rt

900

950

1000

1050

1100

1150

bilingual monolingualGroup

Rea

ctio

n tim

es in

ms

Reaction Times by Group