Skip to content

Instantly share code, notes, and snippets.

@perlatex
Created February 15, 2019 06:05
Show Gist options
  • Save perlatex/15342e0892111f20113a6f8f02f8a9b4 to your computer and use it in GitHub Desktop.
Save perlatex/15342e0892111f20113a6f8f02f8a9b4 to your computer and use it in GitHub Desktop.
Valentine
# learn from https://rpubs.com/dgrtwo/valentine
library(ggplot2)
library(dplyr)
library(gganimate)
heartdf <- tibble(
t = seq(0, 2 * pi, pi / 60),
x = 16 * sin(t)^3,
y = 13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)
)
ggplot(data = heartdf, aes(x, y)) +
geom_path() +
transition_reveal(t)
textdf <- heartdf %>%
select(-t) %>%
tidyr::crossing(t = max(heartdf$t) + 1:15)
ggplot(data = heartdf, aes(x, y)) +
geom_path() +
geom_polygon(data = textdf, fill = "red") +
geom_text(aes(x = 0, y = 0, label = "情人节快乐!!!"),
data = textdf, size = 12, colour = "white" ) +
transition_reveal(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment