Created
August 24, 2019 15:39
-
-
Save founddrama/37eae789ed6bddfa8363087d833df911 to your computer and use it in GitHub Desktop.
Digging into my own collected brewing data with Rstudio and some tidyverse tools.
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
--- | |
title: "Crunching Brew Data" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
library("dplyr") | |
library("ggplot2") | |
library("reshape2") | |
setwd("~") | |
# RE: reading CSV from Google Spreadsheets | |
# https://stackoverflow.com/questions/33713084/download-link-for-google-spreadsheets-csv-export-with-multiple-sheets | |
# | |
# BREW DATA | |
# | |
brew.data <- read.csv("https://docs.google.com/spreadsheets/d/1pIYEBEaHMjfSST8Nbwr6ehsT0njU_K0cgG9BKqV1EDM/gviz/tq?tqx=out:csv&sheet=BrewData") %>% | |
# drop unused columns | |
select(-starts_with("X.Br")) %>% | |
# prices to numbers | |
mutate_at(vars(X., X..12.oz.), ~as.numeric(sub("\\$", "", .))) %>% | |
# percents to numbers | |
mutate_at(vars(Brew.House.Efficiency, ABV..), ~as.numeric(sub("%", "", .))) %>% | |
# dates-as-strings (...as factors) to dates | |
mutate_at(vars(Brew.date, Packaged, Ready.date, Racked), ~as.Date(., format="%m/%d/%Y")) | |
# | |
# MASH DATA | |
# | |
mash.data <- read.csv("https://docs.google.com/spreadsheets/d/1NNg8FCR10g1T_B9z8Aeuy9oL9wZPJTelA22V79QCo98/gviz/tq?tqx=out:csv&sheet=offsets-applied") %>% | |
# remove extraneous columns | |
select_if(~!all(is.na(.))) %>% | |
# dates! | |
mutate_at(vars(Brew.Date), ~as.Date(., format="%m/%d/%Y")) | |
# | |
# YEAST DATA | |
# | |
yeast.data <- read.csv("https://docs.google.com/spreadsheets/d/1MbKuvXEQJGV58vjzOcdTAzcuB5o4JtNExPNzMKCamhI/gviz/tq?tqx=out:csv&sheet=individuals") %>% | |
# remove extraneous columns | |
select_if(~!all(is.na(.))) %>% select(-c(URL)) %>% | |
# dates! | |
mutate_at(vars(ends_with("Date")), ~as.Date(., format="%m/%d/%Y")) | |
# | |
# bubble-per-minute data | |
# | |
bpm.data <- read.csv("https://docs.google.com/spreadsheets/d/1pIYEBEaHMjfSST8Nbwr6ehsT0njU_K0cgG9BKqV1EDM/gviz/tq?tqx=out:csv&sheet=bubbles-per-minute%20data") | |
``` | |
```{r target.vs.original.gravity} | |
ggplot(brew.data %>% filter(Brewed.as == "Tilde Gravitywerks"), | |
aes(Target.Gravity, Original.Gravity)) + | |
#geom_point(aes(color = Brewed.as)) + | |
#labs(color="Brewed As") + | |
geom_point() + | |
ggtitle("Target vs. Actual Original Gravity") + | |
scale_x_continuous(breaks = c(1.040, 1.050, 1.060, 1.070, 1.080, 1.090), | |
labels = c("1.040", "1.050", "1.060", "1.070", "1.080", "1.090")) + | |
xlab("Target Original Gravity") + | |
scale_y_continuous(breaks = c(1.040, 1.050, 1.060, 1.070, 1.080, 1.090, 1.100), | |
labels = c("1.040", "1.050", "1.060", "1.070", "1.080", "1.090", "1.100")) + | |
ylab("Actual Original Gravity") + | |
geom_smooth(method = "lm") + | |
theme(legend.position = "bottom") | |
``` | |
```{r price.over.time} | |
ggplot(brew.data, aes(Brew.date, X..12.oz.)) + | |
geom_point(aes(color=Brewed.as)) + | |
labs(color="Brewed As") + | |
scale_y_continuous(breaks = c(0.5, 1, 1.5, 2, 2.5), | |
labels = c("$0.50", "$1.00", "$1.50", "$2.00", "$2.50")) + | |
ylab("$/12 oz.") + | |
scale_x_date() + xlab("Brew Date") + | |
geom_smooth(method = "lm") + | |
theme(legend.position = "bottom") | |
``` | |
```{r abv.by.batch.size.over.time} | |
ggplot(brew.data, aes(Brew.date, ABV..)) + | |
geom_point(aes(color=Brewed.as, size=Batch.Size.Packaged..gal..)) + | |
guides(size = FALSE) + | |
labs(color="Brewed As") + | |
scale_y_continuous() + | |
ylab("% ABV") + | |
scale_x_date() + xlab("Brew Date") + | |
geom_smooth(method = "lm") + | |
theme(legend.position = "bottom") | |
``` | |
```{r qt.lb.ratio.to.gravity.delta} | |
ggplot(mash.data, aes(qt..lb..ratio, Δ...0.003.)) + | |
geom_point() + | |
scale_y_continuous() + | |
ylab("O.G. delta") + | |
scale_x_continuous() + | |
xlab("qt./lb.") + | |
geom_smooth(method = "lm") + | |
theme(legend.position = "bottom") + | |
coord_cartesian(xlim=c(2,5), ylim=c(-0.03,0.03)) | |
``` | |
```{r yeast.obs.att.vs.starter.size} | |
ggplot(yeast.data, aes(Starter.Size..ml., Obs....Att.)) + | |
geom_point(aes(color = Manufacturer), na.rm=TRUE) + | |
scale_x_continuous() + xlab("Starter Size (ml)") + | |
scale_y_continuous() + ylab("Observed % Apparent Attenuation") + | |
geom_smooth(method = "lm", na.rm=TRUE) + | |
coord_cartesian(xlim = c(500, 2000), ylim=c(60, 90)) | |
``` | |
```{r bpm.chart} | |
# trying - https://stackoverflow.com/questions/28775036/ggplot-line-graph-with-na-values | |
bpm.data2 <- melt(bpm.data, id.var="hours.after.pitching") | |
bpm.data2 <- na.omit(bpm.data2) | |
ggplot(bpm.data2, aes(x=hours.after.pitching, y=value, color=variable)) + | |
geom_line() + | |
theme(legend.position = "none") | |
#geom_smooth(method = "rlm", na.rm = TRUE) | |
``` | |
```{r srm.by.abv} | |
ggplot(brew.data, aes(SRM, ABV..)) + | |
geom_point(na.rm=TRUE, aes(color=SRM)) + | |
#scale_colour_gradient(low="#FEE287", high="#28060A") | |
scale_colour_gradient(low="#FED265", high="#28060A") + | |
ylab("% ABV") | |
``` | |
```{r srm.by.ibu} | |
ggplot(brew.data, aes(ABV.., IBU)) + | |
geom_point(na.rm=TRUE, aes(color=SRM)) + | |
#scale_colour_gradient(low="#FEE287", high="#28060A") | |
scale_colour_gradient(low="#FED265", high="#28060A") + | |
xlab("% ABV") + | |
geom_smooth(method = "lm") | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment