Skip to content

Instantly share code, notes, and snippets.

@chichacha
Created February 15, 2019 04:38
Show Gist options
  • Save chichacha/1ffadc609646f37270620f27159a988c to your computer and use it in GitHub Desktop.
Save chichacha/1ffadc609646f37270620f27159a988c to your computer and use it in GitHub Desktop.
Drawing Heart Shape & Revealing It
## drawing heart!
library(tidyverse)
library(gganimate)
## function to create data frame for heart shape with 100 points.
heart_vertices <- function(xc=0,yc=0,npoints=100,...){
t = seq(-pi,pi, length.out=npoints+1)
x = xc + 16 *(sin(t))^3
y = yc + 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)
df <- tibble(theta=t,x=x,y=y)
return(df)
}
## make the data frame for heart
heart_df <- heart_vertices()
## reveal the heart with gganimate transtion_reveal!
heart_df %>%
ggplot(aes(x=x,y=y)) +
geom_polygon(fill="#E35B5D90") +
geom_path(color="#E35B5D", size=10) +
annotate(label="Happy\nValentine's\nDay",
color="white", family="Helsinki", geom="text", x=0,y=0, size=15,
lineheight=0.8) +
theme_void() +
transition_reveal(along=theta)
@chichacha
Copy link
Author

v_day_heart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment