Skip to content

Instantly share code, notes, and snippets.

@kevinsoo
Last active February 14, 2017 16:37
Show Gist options
  • Select an option

  • Save kevinsoo/e94529f6bcfeccb976b12e5d676bfbbb to your computer and use it in GitHub Desktop.

Select an option

Save kevinsoo/e94529f6bcfeccb976b12e5d676bfbbb to your computer and use it in GitHub Desktop.
Code to create a Valentine's day greeting (2017)
# This code generates a scatterplot with a greeting
# Maybe next year I'll get my wife a real card + flowers
# load libraries
library(tidyverse)
library(gganimate)
library(ggthemes)
# data (greeting can be changed here)
text <- c("Happy", "Valentine's", "Day", "to", "my", "statistically", "significant", "other!", "Though", "the", "holiday", "is", "arbitrary,", "every", "extra", "day", "with", "you", "means", "the", "world", "to", "me!")
x <- runif(length(text), .10, .90)
y <- runif(length(text), .10, .90)
t <- 1:length(text)
df <- data.frame(t, text, x, y)
# plot
p <- ggplot(df, aes(x=x, y=y, frame=t)) +
geom_point(aes(cumulative=TRUE)) +
geom_path(aes(cumulative=TRUE)) +
geom_label(aes(label=text), size=7) +
ylim(c(0,1)) +
xlim(c(0,1)) +
ylab("") +
xlab("") +
theme_fivethirtyeight() +
labs(title="A Valentine's Day Greeting, Part",
subtitle="For Evelyn Yarzebinski, from Kevin Soo",
caption="2/14/2017")
# animate
gg_animate(p)
gg_animate(p, "output.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment