Created
July 17, 2018 20:40
-
-
Save FavioVazquez/2da1abf005ac842110361cd1d745d0e8 to your computer and use it in GitHub Desktop.
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
#library(devtools) | |
#install_github("ropensci/drake") | |
library(dplyr) | |
library(ggplot2) | |
library(drake) | |
# Donwload neccesary data | |
drake_example("main") | |
# Check if data and report exists | |
file.exists("main/raw_data.xlsx") | |
file.exists("main/report.Rmd") | |
# Crate a custom plot function | |
create_plot <- function(data) { | |
ggplot(data, aes(x = Petal.Width, fill = Species)) + | |
geom_histogram(binwidth = 0.25) + | |
theme_gray(20) | |
} | |
plot_lm <- function(data) { | |
ggplot(data = data, aes(x = Petal.Width, y = Sepal.Width)) + | |
geom_point(color='red') + | |
stat_smooth(method = "lm", col = "red") | |
} | |
# Create the plan | |
plan <- drake_plan( | |
raw_data = readxl::read_excel(file_in("main/raw_data.xlsx")), | |
data = raw_data %>% | |
mutate(Species = forcats::fct_inorder(Species)) %>% | |
select(-X__1), | |
hist = create_plot(data), | |
cor = cor(data$Petal.Width,data$Sepal.Width), | |
fit = lm(Sepal.Width ~ Petal.Width + Species, data), | |
plot = plot_lm(data), | |
report = rmarkdown::render( | |
knitr_in("main/report.Rmd"), | |
output_file = file_out("main/report.html"), | |
quiet = TRUE | |
) | |
) | |
plan | |
# Excecute the plan | |
make(plan) | |
# Interactive graph: hover, zoom, drag, etc. | |
config <- drake_config(plan) | |
vis_drake_graph(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment