Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active February 25, 2016 21:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeroen/fa60515cd84dd1ce6e61 to your computer and use it in GitHub Desktop.
Save jeroen/fa60515cd84dd1ce6e61 to your computer and use it in GitHub Desktop.
library(magrittr)
library(dplyr)
library(nycflights13)
library(evaluate)
library(ggplot2)
# Define the plot
makeplot <- function(mydata){
date <- as.Date(paste("2013", mydata[1,"month"], mydata[1,"day"], sep="-"))
ggplot(mydata, aes(distance, arr_delay)) +
geom_point() + geom_smooth(se = FALSE) +
xlim(0, 3000) + ylim(0, 500) +
xlab("Distance") + ylab("Delay") +
ggtitle(format(date, "%A, %B %d, %Y"))
}
# Render and store the plots
sub_plots <- flights %>%
filter(!is.na(distance), !is.na(arr_delay)) %>%
group_by(month, day) %>%
do(plot = evaluate("makeplot(.)", keep_warning=FALSE)[[3]])
# Play animation in rstudio
sub_plots %>% do(out = {print(.$plot); Sys.sleep(.10)})
@stanstrup
Copy link

github version of dplyr results in:

Error in .Call("dplyr_resolve_vars", PACKAGE = "dplyr", new_groups, names) : 
  "dplyr_resolve_vars" not available for .Call() for package "dplyr"

for the grouping step.

CRAN version gives:

Error in evaluate("makeplot(.)", keep_warning = FALSE)[[3]] : 
  subscript out of bounds
In addition: Warning messages:
1: Removed 359 rows containing non-finite values (stat_smooth). 
2: Removed 359 rows containing missing values (geom_point). 

for the first do step.

@stanstrup
Copy link

Scratch that. Runs when I also have CRAN version of ggplot2. It does however seem to get stuck at 77% of the first "do" on my machine.

@Nowosad
Copy link

Nowosad commented Dec 24, 2015

Same here - process get stuck at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment