qplot

## Agenda

Learn to quickly build a set of plots that are routinely used to explore data:

• Scatter Plot
• Bar Plot
• Box Plot
• Line Chart
• Histogram

## Introduction

Shortcut designed for those familiar with base plots. You can quickly produce a number of different types of plots. Below are the key arguments:

• x : data for X axis
• y : data for Y axis
• data : a data frame or a tibble
• geom : symbols to represent data
• fill : color for filled symbols
• color: color for other symbols
• shape: shape of the geom
• size : size of the symbol

## Scatter Plot - Part 1

### Example

qplot(x = hp, y = mpg, data = mtcars)

### Instructions

• map x to disp
• map y to mpg
• map data to mtcars
# scatter plot using qplot
qplot(x = ___, y = ___, data = ___)
qplot(x = disp, y = mpg, data = mtcars)

## Scatter Plot - Part 2

### Example

qplot(hp, mpg, data = mtcars, geom = c('point', 'line'))

### Instructions

• map geom to point and line
qplot(disp, mpg, data = mtcars, geom = c('____', '____'))
qplot(x = disp, y = mpg, data = mtcars, geom = c('point', 'line'))

## Scatter Plot - Part 3

### Example

qplot(hp, mpg, data = mtcars, color = gear)

### Instructions

• map color to cyl
qplot(disp, mpg, data = mtcars, color = ____)
qplot(x = disp, y = mpg, data = mtcars, color = 'cyl')

## Bar Plot - Part 1

### Example

qplot(x = gear, data = mtcars, geom = c('bar'))

### Instructions

• map x to cyl
• map geom to bar
qplot(x = ____, data = mtcars, geom = c('____'))
qplot(x = cyl, data = mtcars, geom = 'bar')

## Bar Plot - Part 2

### Example

qplot(x = gear, data = mtcars, geom = c('bar'), fill = vs)

### Instructions

• map x to cyl
• map fill to am
qplot(x = ____, data = mtcars, geom = c('bar'), fill = ____)
qplot(x = cyl, data = mtcars, geom = c('bar'), fill = am)

## Box Plot

### Example

qplot(x = cyl, y = disp, data = mtcars, geom = c('boxplot'))
## Warning: Continuous x aesthetic -- did you forget aes(group=...)?

### Instructions

• map x to gear
• map y to mpg
• map geom to boxplot
qplot(x = ____, y = ____, data = mtcars, geom = c('______'))
qplot(x = gear, y = mpg, data = mtcars, geom = 'boxplot')

## Line Chart

### Example

qplot(x = ____, y = ____, data = economics, geom = c('____'))

### Instructions

• map x to date
• map y to umemploy
• map geom to line
qplot(x = ____, y = ____, data = economics, geom = c('____'))
qplot(x = date, y = unemploy, data = economics, geom = c('line'))

## Histogram

### Example

qplot(x = disp, data = mtcars, bins = 6)

### Instructions

• map x to mpg
• set bins to 5
qplot(x = ____, data = mtcars, bins = ____)
qplot(x = mpg, data = mtcars, bins = 5)