Skip to content

Instantly share code, notes, and snippets.

@cengel
Created July 23, 2016 06:25
Show Gist options
  • Save cengel/cf97fb20ec55e3962fbb13974f965920 to your computer and use it in GitHub Desktop.
Save cengel/cf97fb20ec55e3962fbb13974f965920 to your computer and use it in GitHub Desktop.
# May have to install xckd fonts through FontBook.
library(xkcd)
# the data to make the bars
df <- data.frame(x=c(1, 3), y=c(20, 2))
# the figures
ratioxy <- diff(range(df$x)) / diff(range(df$y))
mapping <- aes(x, y,
scale,
ratioxy,
angleofspine,
anglerighthumerus,
anglelefthumerus,
anglerightradius,
angleleftradius,
anglerightleg,
angleleftleg,
angleofneck)
stickfigs <- data.frame( x=c(1.5, 2), y=c(16, 1.5),
scale = 1.2,
ratioxy = ratioxy,
angleofspine = c(2.2, -1.2), #-pi/2
anglerighthumerus = c(0.5, -0.5), #c(-pi/6, -pi/6)
anglelefthumerus = c(3.2, -2), #c(-pi/2 - pi/6, -pi/2 - pi/6),
anglerightradius = c(1, -0.6), #c(pi/5, -pi/5),
angleleftradius = c(3.8, -0.6), #c(pi/5, -pi/5),
angleleftleg = c(0.2, 0.2), #3*pi/2 + pi / 12,
anglerightleg = c(1.1, -0.2), #3*pi/2 - pi / 12,
angleofneck = c(2, 5)) #runif(1, 3*pi/2-pi/10, 3*pi/2+pi/10)
# plot it
ggplot() + xkcdrect(aes(xmin=x - 0.1, ymin=0.8, xmax=x + 0.1, ymax=y), df, fill="white") +
xkcdaxis(xrange=c(0, 4), yrange=c(0, 18)) +
annotate("text", x=1, y=-0.3, label="times Ashley has fallen \n off the R cliff", family="xkcd") +
annotate("text", x=3, y=0.2, label="Times she wishes to admit", family="xkcd") +
xkcdman(mapping, stickfigs) +
ylab("") + xlab("") +
theme(axis.text = element_blank(),
axis.ticks = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment