R Markdown

Let’s create a function that will plot a love heart. To do this i’ll create one half of the heart with .01(-t^2+40t+1200)cos(pit/180) then inverse it. The rest is text/colour edit. The function allows you to also add custom text in it.

heart1 = function(text){
    t = seq(0,60,len=100)
    x11(width=6, height=8)
    plot(c(-8,8),c(0,20),type='n',axes=FALSE,xlab='',ylab='')
    x = -.01*(-t^2+40*t+1200)*sin(pi*t/180)
    y = .01*(-t^2+40*t+1200)*cos(pi*t/180)
    lines(x,y, lwd=4, col="hotpink")
    lines(-x,y, lwd=4, col="hotpink")
    text(0,8,text,col='black',cex=2.5)
}

Including Plots

Plotting this looks like:

heart1("TESTING")

We could even make a gif of a love heart by transforming the object like so:

# library(animation)
# saveGIF({
#   for(i in 1:150){
#   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*t)
#   dat$y=yhrt(dat$t)
#   dat$x=xhrt(dat$t)
#   with(plot(dat$x,dat$y, type="l", xlim = c(-100  , i ^ 2 / 10 )) ) 
#  } 
# }, interval = 0.1, ani.width = 550, ani.height = 550)

Currently broken and in testing