STATS 787
Effective Data Visualisations

Reminders

  • Lab 10 (due week 12)

The Principle of Proportional Ink

ggplot(mtcars) +
    geom_bar(aes(x=am))

ggplot(mtcars) +
    geom_bar(aes(x=am)) +
    coord_cartesian(ylim=c(10, NA))

ggplot(mtcars) +
    geom_bar(aes(x=am)) +
    scale_y_continuous(limits=c(10, NA))
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_bar()`).

ggplot(mtcars) +
    geom_point(aes(disp, mpg, size=hp))

ggplot(mtcars) +
    geom_point(aes(disp, mpg, size=hp)) +
    scale_radius()

ggplot(mtcars) +
    geom_point(aes(disp, mpg, size=hp)) +
    scale_size_area()

Overplotting

ggplot(mtcars) +
    geom_point(aes(disp, mpg), alpha=.3, size=2)

ggplot(mtcars) +
    geom_jitter(aes(disp, mpg), alpha=.3, size=2)

ggplot(mtcars) +
    geom_jitter(aes(disp, mpg), alpha=.3, size=2, 
                width=10, height=1)

ggplot(df) +
    geom_point(aes(V1, V2))

ggplot(df) +
    geom_point(aes(V1, V2), alpha=.2)

ggplot(df) +
    geom_bin2d(aes(V1, V2))

ggplot(df) +
    geom_hex(aes(V1, V2))

ggplot(df) +
    geom_density2d(aes(V1, V2))

ggplot(df) +
    geom_density2d_filled(aes(V1, V2))

Colour

ggplot(mtcars) +
    geom_point(aes(disp, mpg, colour=gear))

ggplot(mtcars) +
    geom_point(aes(disp, mpg, colour=factor(gear)))

ggplot(mtcars) +
    geom_point(aes(disp, mpg, colour=factor(gear))) +
    scale_colour_manual(values=2:4)

ggplot(mtcars) +
    geom_point(aes(disp, mpg, colour=factor(gear))) +
    scale_colour_manual(values=colorspace::deutan(2:4))

ggplot(mtcars) +
    geom_point(aes(disp, mpg, colour=cut(wt, 10)))

Redundant Coding

ggplot(mtcars) +
    geom_point(aes(disp, mpg, colour=factor(gear), shape=factor(gear)))

library(ggforce)
ggplot(mtcars, aes(disp, mpg)) +
    geom_mark_hull(aes(fill=factor(gear), label=gear)) +
    geom_point() +
    theme(legend.position="none")

Small Multiples

ggplot(mtcars) +
    geom_point(aes(disp, mpg)) +
    facet_wrap(vars(gear))

Labels

ggplot(mtcars) +
    geom_point(aes(disp, mpg))

ggplot(mtcars) +
    geom_point(aes(disp, mpg)) +
    labs(title="Fuel Efficiency (in the 1970s)") +
    xlab(expression(paste("Engine Displacement (", "in"^3, ")"))) +
    ylab("Miles per Gallon")

ggplot(mtcars) +
    geom_point(aes(disp, mpg)) +
    labs(title="Fuel Efficiency",
         subtitle="(in the 1970s)") +
    xlab(expression(paste("Engine Displacement (", "in"^3, ")"))) +
    ylab("Miles per Gallon") +
    theme(plot.title=element_text(size=18))

The Data-Ink Ratio

ggplot(mtcars) +
    geom_point(aes(disp, mpg))

ggplot(mtcars) +
    geom_point(aes(disp, mpg)) +
    theme_minimal()

ggplot(mtcars) +
    geom_point(aes(disp, mpg)) +
    theme_minimal() +
    theme(panel.grid.major=element_blank(),
          panel.grid.minor=element_blank())

ggplot(mtcars) +
    geom_point(aes(disp, mpg)) +
    theme_void()