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

Data Visualization

Chapter 3. Data Visualization in R

Iñaki Úcar

Department of Statistics | uc3m-Santander Big Data Institute

Master in Computational Social Science

Licensed under Creative Commons Attribution CC BY 4.0 Last generated: 2023-01-25

1 / 13

Directory of Visualizations

Based on The R Graph Gallery

2 / 13

Evolution

< Contents

Line plot Area Stacked area Stream chart Time series


  • Visualization of the evolution of series
  • Individual data points are not important
  • When x is time -> time series
3 / 13

Evolution Line plot

< Contents

ggstream::blockbusters |>
filter(genre == "Action") |>
ggplot() +
aes(year, box_office) +
geom_line()

4 / 13

Evolution Area

< Contents

ggstream::blockbusters |>
filter(genre == "Action") |>
ggplot() +
aes(year, box_office) +
geom_area()

5 / 13

Evolution Time series

< Contents

ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1))) |>
filter(genre == "Action") |>
ggplot() +
aes(date, box_office) +
geom_line()

6 / 13

Evolution Time series

< Contents

ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1))) |>
ggplot() +
aes(date, box_office) +
geom_line(aes(color=genre))

7 / 13

Evolution Time series

< Contents

ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1))) |>
mutate(genre = forcats::fct_reorder2(
genre, year, box_office)) |>
ggplot() +
aes(date, box_office) +
geom_line(aes(color=genre))

8 / 13

Evolution Time series

< Contents

df <- ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1)))
text <- df |>
group_by(genre) |>
slice(n())
ggplot(df) +
aes(date, box_office,
color=genre) +
geom_line() +
geom_text(aes(label=genre),
text, hjust=-0.1) +
expand_limits(
x=as.Date("2024-01-01")) +
theme(legend.position="none")

9 / 13

Evolution Stacked area

< Contents

ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1))) |>
ggplot() +
aes(date, box_office) +
geom_area(aes(fill=genre))

10 / 13

Evolution Streamchart

< Contents

ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1))) |>
ggplot() +
aes(date, box_office) +
ggstream::geom_stream(
aes(fill=genre),
type="ridge")

11 / 13

Evolution Streamchart

< Contents

ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1))) |>
ggplot() +
aes(date, box_office) +
ggstream::geom_stream(
aes(fill=genre),
type="mirror")

12 / 13

Evolution Streamchart

< Contents

ggstream::blockbusters |>
mutate(date = as.Date(
ISOdate(year, 1, 1))) |>
ggplot() +
aes(date, box_office) +
ggstream::geom_stream(
aes(fill=genre),
type="proportional")

13 / 13

Directory of Visualizations

Based on The R Graph Gallery

2 / 13
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
sToggle scribble toolbox
Esc Back to slideshow