Lesson 1: R Basics - WordPress.com › 2016 › 02 › ... · Lesson 1: R Basics. Make an R Project...

Preview:

Citation preview

Lesson 1: R Basics

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

variable

levels of a variable

data frame

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

dplyr

new data frame

dplyr

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

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

original data frame

new data frame

dplyr

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

original data frame

new data frame

pipe

dplyr

original data frame

new data frame

pipe

verb

dplyr

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

original data frame

new data frame

pipe

verb

variable

dplyr

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

original data frame

new data frame

pipe

verb

variable

level of a variable

dplyr

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

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. <, >)

> dim(data)[1] 400 3

> dim(data_bl)[1] 200 3

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. >, <)

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. >, <)

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. >, <)

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. >, <)

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. >, <)

> dim(data)[1] 400 3

> dim(data_bl)[1] 153 3

ggplot2

ggplot2

plot

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

data.plot

ggplot2

plotinitializes

plot

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

data.plot

ggplot2

plotinitializes

plot

data frame

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

data.plot

ggplot2

plotinitializes

plot

data frameaesthetics

to plot

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

data.plot

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

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

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

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

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

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