Skip to content

Instantly share code, notes, and snippets.

library(dplyr)
library(ggthemes)
library(ggplot2)
anes <- rio::import("~/Dropbox/anes_timeseries_cdf_dta/anes_timeseries_cdf_stata13.dta")
anes$year <- anes$VCF0004
anes$demrep <- as.factor(car::recode(as.numeric(anes$VCF0301),"1:3='Democrat';5:7='Republican';else=NA"))
anes$VCF0218[anes$VCF0218>97]=NA
anes$VCF0224[anes$VCF0224>97]=NA
Red Green Blue Violet
Korn, Naomi H Rau, Sarika U Yan, Jason H Lacewala, Aamir D
Chen, Stephen L Zakoian, Martin J Hau, Vinh D Lane, Kaitlyn D
Slavitt, Zachary L Zongo, Josias J Alvarez-Sanchez, David E Zhang, Ian L
Leblanc, Matthew D Lee, Iris
mpg %>% group_by(cyl) %>% summarise(hwy=mean(hwy)) -> forplot
forplot$order <- c(1,2,3,4)
a <- ggplot(forplot, aes(x = cyl %>% as.factor(), y = hwy)) +
geom_bar(stat = 'identity')
plot <- a + transition_reveal(order)
animate(plot,nframes = 4,renderer = file_renderer("presentation//", prefix = "cars", overwrite = TRUE),
res=150,width=5,height=5,units="in")
zero1 <- function(x, minx=NA, maxx=NA){
res <- NA
if(is.na(minx)) res <- (x - min(x,na.rm=T))/(max(x,na.rm=T) -min(x,na.rm=T))
if(!is.na(minx)) res <- (x - minx)/(maxx -minx)
res
}