Last active
January 8, 2022 13:07
-
-
Save Akiyah/0c7890578a9a7e2a4aaaced760c09d02 to your computer and use it in GitHub Desktop.
graph_animation
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
#install.packages("ggplot2") | |
library(ggplot2) | |
path <- '~/Dropbox/tech/graph_animation' | |
fun <- function(x) 2^x | |
for (j in seq(66, 98, by=1)) { | |
p <- ggplot(data=data.frame(X=c(-1, 10 + 1)), aes(x=X)) | |
p <- p + stat_function(fun=fun) | |
p <- p + coord_cartesian(xlim=c(0, 10), ylim=c(0, fun(j / 10))) | |
p <- p + theme_bw() | |
p <- p + scale_x_continuous(breaks=seq(0, 10, length=11)) | |
p <- p + scale_y_continuous(breaks=seq(0, 1000, length=21)) | |
p <- p + geom_hline(yintercept=0) | |
p <- p + geom_vline(xintercept=0) | |
p <- p + labs(x="x", y="2^x") | |
print(p) | |
ggsave(file=paste(path, "/graph_", j, ".png", sep=""), plot=p, dpi=100, width=4.8, height=6.4) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment