-
-
Save AABoyles/9004943 to your computer and use it in GitHub Desktop.
Animated Beating Heart in R
This file contains hidden or 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
############################################################ | |
## Title: Animated Beating Heart in R | |
## Author: Jared Knowles | |
## Forked: Tony Boyles | |
## Date: February 14, 2014 | |
############################################################ | |
library(animation) | |
library(ggplot2) | |
t<-seq(-100,100,length.out=2010) | |
x<-16*sin(t)^3 | |
y<-(13*cos(t))-(5*cos(2*t))-(2*cos(3*t))-(cos(4*t)) | |
heart<-data.frame(x=x,y=y,order=t) | |
if(!file.exists("heart.gif")){ | |
file.create("heart.gif") | |
} | |
ani.options(outdir=getwd(),imgdir=getwd(),tempdir=getwd()) | |
saveGIF({ | |
for(i in c(seq(0.85,1.00,by=.01),seq(0.99,0.85,by=-.01),seq(0.86,0.91,by=.01),seq(.90,0.86,by=-.01))) | |
print( | |
ggplot(heart, aes(i*x,i*y)) + | |
geom_path(color="red", size=5)+ | |
xlim(-16,16)+ | |
ylim(-17,12)+ | |
labs(x='', y='')+ | |
theme_bw()+ | |
theme( | |
axis.text.x=element_blank(), | |
axis.ticks=element_blank(), | |
axis.text.y=element_blank()) | |
) | |
},movie.name="heart.gif",interval=0.03,ani.width=300,ani.height=300,convert='convert') |
...or download the raw version and open it in an image previewer...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you can't see it beating, that's because most webservers will serve gifs as jpgs, which causes the browser to view them as static. Try running the R Code to create your own.