Skip to content

Instantly share code, notes, and snippets.

@ateucher
Last active January 18, 2019 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateucher/d99453e01fb121a6b4599e724121d0aa to your computer and use it in GitHub Desktop.
Save ateucher/d99453e01fb121a6b4599e724121d0aa to your computer and use it in GitHub Desktop.
library(datasauRus)
library(ggplot2)
library(ggrepel)
library(viridisLite)
is_equal <- function(x, y, ...) {
vapply(x, function(i) identical(all.equal(i, y, ...), TRUE), FUN.VALUE = logical(1))
}
up <- 12
dino_data <- datasaurus_dozen[datasaurus_dozen$dataset == "dino", ]
dino_data$x <- -dino_data$x + 100
dino_data$y <- dino_data$y + up
dino_data$colour <- (dino_data$x + dino_data$y) / 2
dino_data$label <- NA_character_
dino_data$label[is_equal(dino_data$x, 64.3590) & is_equal(dino_data$y - up, 79.8718)] <- "Good Luck Steph\nWe'll Miss You!"
steph_code <- "attributes(Steph) <- c('smart','fun','committed')
while(between(Sys.Date(),'2007-02-01','2019-01-19')) {
class(Steph) <- 'ENV'
}
if (Sys.Date() >= '2019-01-21') {
class(Steph) <- 'IDD'
}"
# The font sizes make it look crazy in the RStudio plot viewer, but the final png looks good
(p <- ggplot(dino_data, aes(x = x, y = y, label = label, colour = colour)) +
geom_point(size = 10) +
scale_colour_viridis_c(direction = -1, guide = "none") +
scale_y_continuous(limits = c(0, 140)) +
scale_x_continuous(limits = c(0, 130)) +
geom_label_repel(size = 20, nudge_x = 31, nudge_y = 35, label.r = unit(3, "lines"),
point.padding = 2, label.padding = 1.5) +
annotate("label", size = 7, family = "Iosevka", fontface = "bold",
x = 62.5, y = 13, hjust = 0, label = steph_code,
label.r = unit(0, "lines"), label.padding = unit(0.5, "lines"),
colour = viridis(2)[1]) +
theme(axis.text = element_text(size = 16),
axis.title = element_text(size = 16)))
ggsave("steph_cake.png", p, width = 16, height = 12, dpi = 240)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment