Today we have something completely different. We will construct a Valentine using R. The idea came from the #rstats community.
First we need a Valentine function. Let’s build one and then create a dataframe to plot. The function code comes from Daniel Marcelino via Mara Averick.
dat <- data.frame(t=seq(0, 2*pi, by=0.1))
xhrt <- function(t){16*sin(t)^3}
yhrt <- function(t){13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*5)}
dat$y=yhrt(dat$t)
dat$x=xhrt(dat$t)
Now, plot our Valentine using ggplot2. It took me a while to figure out how to use geom_polygon(). I like this better than base graphics. I subsequently discovered that David Robinson had come up with a similar aporach. I added his call to coord_fixed() and kept theme_void where he used theme_minimal().
library(ggplot2)
plt <- ggplot(dat, aes(x=x, y=y)) +
geom_polygon(color="darkred", fill="darkred") +
coord_fixed() +
theme_void()
print(plt)

Ideas from the rstats community help each of us to refine ideas.