Created
February 14, 2019 13:58
-
-
Save perlatex/0a4f103c28d115025f28e9f9c01b5201 to your computer and use it in GitHub Desktop.
create heart for valentine's day using ggplot2 and gganimate
This file contains 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
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) | |
) | |
textdf = tibble(t = max(heartdf$t) + 1:15) | |
ggplot(data = heartdf, aes(x, y)) + | |
geom_polygon(aes(group = 1), fill = "red") + | |
geom_text(aes(x = 0, y = 0, label = "情人节快乐!!!"), | |
data = textdf, size = 12, colour = "white") + | |
transition_reveal(t) | |
anim_save("mygirl.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment