Last active
December 14, 2015 16:04
-
-
Save kevinsoo/4c9a88bd8e91296aae7e to your computer and use it in GitHub Desktop.
Code used to create Kevin & Evelyn's Save The Date! Inspired by xkcd.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### This code was used to create an xkcd-themed graph used for our Save The Date | |
| # Import libraries | |
| library("ggplot2") | |
| library("xkcd") | |
| # Create data for plotting | |
| Evelyn <- sin(1/(1:40)^1.5) | |
| Kevin <- -sin(1/(1:40)^1.5) | |
| t <- c(1:40) | |
| wedding <- data.frame(t, Kevin, Evelyn) | |
| # For .jpg export (1800 x 1200) | |
| ggplot(wedding, aes(x=t)) + | |
| geom_path(aes(y=Evelyn+rnorm(40,0,0.01)), size=4, color="red") + | |
| geom_path(aes(y=Kevin+rnorm(40,0,0.01)), size=4) + | |
| geom_text(x=38, y=-.10, label="Kevin", size=25, family="xkcd") + | |
| geom_text(x=38, y=.10, label="Evelyn", size=25, color="red", family="xkcd") + | |
| geom_point(x=t[40], y=Kevin[40], size=5) + | |
| geom_point(x=t[40], y=Evelyn[40], size=5, color="red") + | |
| geom_text(x=22, y=.6,label="Save the Date!", size=70, family="xkcd") + | |
| geom_text(x=22, y=.35,label="April 30, 2016", size=30, family="xkcd") + | |
| geom_text(x=22, y=-.4,label="Invitation to follow...", size=30, family="xkcd") + | |
| geom_point(x=38, y=0.01, size=120, shape=0) + | |
| geom_text(x=38, y=-.2, label="Getting married!", size=16, family="xkcd") + | |
| theme_xkcd() + xkcdaxis(range(1:42), range(c(-.5,.9)), size=2) + | |
| xlab("Time") + ylab("Location of heart") + | |
| theme(axis.text=element_blank(), axis.title=element_text(size=40)) | |
| # For PDF export (4' x 6') | |
| ggplot(wedding, aes(x=t)) + | |
| geom_path(aes(y=Evelyn+rnorm(40,0,0.01)), size=1.5, color="red") + | |
| geom_path(aes(y=Kevin+rnorm(40,0,0.01)), size=1.5) + | |
| geom_text(x=39, y=-.10, label="Kevin", size=6, family="xkcd") + | |
| geom_text(x=39, y=.10, label="Evelyn", size=6, color="red", family="xkcd") + | |
| geom_point(x=t[40], y=Kevin[40], size=2) + | |
| geom_point(x=t[40], y=Evelyn[40], size=2, color="red") + | |
| geom_text(x=22, y=.6, label="Save the Date!", size=16, family="xkcd") + | |
| geom_text(x=22, y=.35, label="April 30, 2016", size=8, family="xkcd") + | |
| geom_text(x=22, y=-.4, label="Invitation to follow...", size=8, family="xkcd") + | |
| geom_point(x=39, y=0.01, size=30, shape=0) + | |
| geom_text(x=39, y=-.25,label="Getting married", size=4, family="xkcd") + | |
| theme_xkcd() + xkcdaxis(range(1:42), range(c(-.5,.9))) + | |
| theme(axis.text=element_blank()) + xlab("Time") + ylab("Location of heart") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment