Skip to content

Instantly share code, notes, and snippets.

@hanowell
Last active February 17, 2017 17:55
Show Gist options
  • Save hanowell/4bc3dd7e09167a4d1ab3ee9ea682a32e to your computer and use it in GitHub Desktop.
Save hanowell/4bc3dd7e09167a4d1ab3ee9ea682a32e to your computer and use it in GitHub Desktop.
Here is some code to make some plots demonstrating the lie factor that results from using nested donut plots when you should just use a bar chart.
# Clear. Dat. Workspace.
rm(list = ls())
# Load. Dem. Packages.
library(tidyverse)
# Create. Dat. Data.
dat <- data.frame(category = LETTERS[1:4],
fraction = c(0, 20, 30, 50)) # Extra zero datapoint to keep hole in the donut.
# Create a bar chart that isn't bullshit.
not_bullshit<-
dat[2:4, ] %>%
ggplot(aes(x = category, y = fraction)) +
geom_bar(stat = "identity", fill = "gray") +
geom_hline(yintercept = dat$fraction[2], color = "black") +
ylim(0, 100) +
xlab(NULL) +
ylab(NULL) +
labs(title = "NOT BULLSHIT",
subtitle = "Line creates lines of equal length") +
theme_minimal() +
theme(panel.grid = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())
# Put the exact same plot onto polar coordinates for insta-bullshit.
bullshit <-
not_bullshit %+%
dat +
coord_polar(theta = "y", start = pi, direction = 1) +
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank()) +
labs(title = "BULLSHIT",
subtitle = "Line creates lines of different length")
# Compare the non-bullshit to the bullshit.
not_bullshit
bullshit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment