Enhancing graphics

Materials for class on Tuesday, December 4, 2018

Contents

Slides

No slides today!

Live code

Use this link to see the code that I’m actually typing:

I’ve saved the R script to Dropbox, and that link goes to a live version of that file. Refresh or re-open the link as needed to copy/paste code I type up on the screen.

Sharing graphics, code, and analysis

Entire projects:

Refining and enhancing interactive plots

This all goes beyond the scope of this class, because interactive HTML plots all require knowledge of JavaScript and we don’t have time in this class to learn a second programming language.Even in a 3-credit version of this class I wouldn’t cover JavaScript and D3—it would require its own class.

But there are some cool resources for making and enhancing interactive plots:

Refining and enhancing static plots

Install a vector image editor

Make an image and refine it

Data: Nathan’s Famous Hot Dog contest winners Data originally from FlowingData.

Plot with transparent background:

library(tidyverse)
hotdogs <- read_csv("https://datavizf18.classes.andrewheiss.com/data/hot-dog-contest-winners.csv") %>%
  rename(dogs = `Dogs eaten`, record = `New record`) %>%
  mutate(record = factor(record))
plot_hotdogs <- ggplot(hotdogs, aes(x = Year, y = dogs, fill = record)) + 
  geom_col() + 
  scale_fill_manual(values = c("grey80", "#FC7300")) +
  scale_x_continuous(breaks = seq(1980, 2010, 2), expand = c(0, 0)) +
  scale_y_continuous(breaks = seq(0, 70, 10), expand = c(0, 0)) +
  guides(fill = FALSE) +
  labs(y = "Hot dogs and buns", x = NULL) +
  theme_minimal() +
  theme(panel.background = element_rect(fill = "transparent", colour = NA),
        plot.background = element_rect(fill = "transparent", colour = NA),
        axis.ticks.x = element_line(size = 0.25),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(size = 0.5, linetype = "dashed"),
        panel.grid.minor = element_blank())

plot_hotdogs

ggsave(plot_hotdogs, filename = "output/hotdogs.pdf", device = cairo_pdf,
       width = 7, height = 4, units = "in", bg = "transparent")

Text for annotations:

Original enhanced plot:

Enhanced hot dog eating contest graph

Enhanced hot dog eating contest graph

Clearest and muddiest things

Go to this form and answer these two questions:

  1. What was the muddiest thing from class today? What are you still wondering about?
  2. What was the clearest thing from class today? What was the most exciting thing you learned?

I’ll compile the questions and send out answers after class.