Box Plot

## Introduction

### Agenda

• build box plots
• modify box
• color
• fill
• alpha
• line size
• line type
• modify outlier
• color
• shape
• size
• alpha

## Data

### Introduction

ecom

### Data Dictionary

• id: row id
• referrer: referrer website/search engine
• os: operating system
• browser: browser
• device: device used to visit the website
• n_pages: number of pages visited
• duration: time spent on the website (in seconds)
• repeat: frequency of visits
• country: country of origin
• purchase: whether visitor purchased
• order_value: order value of visitor (in dollars)

## Plot - Part 1

### Example

ggplot(ecom) +
geom_boxplot(aes(x = factor(1), y = n_visit))

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(1), y = n_visit))
ggplot(ecom) +
geom_boxplot(aes(x = factor(1), y = n_visit))

## Plot - Part 2

### Example

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit))

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit))
ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit))

## Horizontal Box Plot

### Example

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit)) +
coord_flip()

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit)) +
coord_flip()
ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit)) +
coord_flip()

## Notch

### Example

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit),
notch = TRUE) 

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit),
notch = TRUE) 
ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = n_visit),
notch = TRUE) 

• color
• shape
• size
• alpha

## Outliers - Practice

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration),
outlier.color = 'red', outlier.shape = 23, outlier.size = 3)
ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration),
outlier.color = 'red', outlier.shape = 23, outlier.size = 3)

## Fill & Color - Practice 1

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration),
fill = c('blue', 'red', 'green')) 
ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration),
fill = c('blue', 'red', 'green')) 

## Fill & Color - Practice 2

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration,
fill = factor(device))) 
ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration,
fill = factor(device))) 

## Fill & Color - Practice 3

### Instructions

ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration,
color = factor(device))) 
ggplot(ecom) +
geom_boxplot(aes(x = factor(device), y = duration,
color = factor(device)))