+ - 0:00:00
Notes for current slide
Notes for next slide

Data visualization review

Dr. Dogucu

2020-01-22

1 / 18

Review

Which R functions do you recall from last discussion?

What is the shortcut for %>%?

2 / 18

Data

We will be using titanic_train dataset from the titanic package.

Glimpse at the data. Does everything look like it should?

3 / 18

Who uses ggplot? Some examples

BBC

FiveThirtyEight

Master List

4 / 18

Three steps of basic visualization with ggplot2 package

  1. Make some space (this soon will make sense) using the ggplot() function.

  2. Draw your axes using aes() function.

  3. Add your plot, whether it is histogram, bar plot or something else. We will call these geom objects.

5 / 18

Planning for ggplot

For every plot,

1) Decide, what variables to use.
2) Decide which variable is on which axes.
3) Decide what kind of plot it is.

6 / 18
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Why are we getting this warning?

7 / 18

What step of the code is binwidth related to?

8 / 18

Cheatsheet

Look at the ggplot cheatsheet. Moving on you will attempt at making the plot by finding the geom object from your cheatsheet.

9 / 18



10 / 18

You Attempt This First

Make a plot that shows the relationship between age of the passenger and the fare that they paid. Comment whether older passengers bought more expensive tickets.

11 / 18

12 / 18

Color

titanic_train %>%
ggplot(aes(x = Fare )) +
geom_histogram(color = "salmon")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

13 / 18

Fill

titanic_train %>%
ggplot(aes(x = Fare)) +
geom_histogram(fill = "salmon")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

14 / 18

Shape

titanic_train %>%
ggplot(aes(x = Age, y = Fare )) +
geom_point(shape = 4)

15 / 18

More colors




bit.ly/colors-r

16 / 18

More shapes




bit.ly/shapes-r

17 / 18

Stacked bar plot

Can you guess where the fill argument will go for this stacked bar plot?

18 / 18

Review

Which R functions do you recall from last discussion?

What is the shortcut for %>%?

2 / 18
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow