#plotting growth curve with additional data encoded as the color fill of a geom_tile
# in this case, it is pH
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(growthcurver)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
load("growth.ph.rdata")
lb <- growth.ph %>% filter(medium=="lb")
nay <- growth.ph %>% filter(medium=="nay")
model.lb <- SummarizeGrowth(lb$time,lb$od)
model.nay <- SummarizeGrowth(nay$time,nay$od)
lb$model <- predict(model.lb$model)
nay$model <- predict(model.nay$model)
growth.ph <- rbind(lb,nay)
growth.ph %>% ggplot() +
geom_point(aes(x=time, y=od), alpha=1/2) +
geom_tile(aes(x=time, y=11, fill=pH), width=1.5) +
facet_grid(medium ~ .) +
scale_fill_gradient(low = "red",high = "green") +
geom_line(aes(time,model), color="red", alpha=0.5)+
theme_bw()

# the pH measurements are overlapping, therefore no alpha here
#or, to express the pH as the points' color
p <- growth.ph %>% ggplot() +
geom_point(aes(x=time, y=od, color=pH)) +
facet_grid(medium ~ .) +
geom_line(aes(time,model), color="red", alpha=0.5)+
scale_color_gradient(low="red", high="green") +
theme_bw()
p

#or, using plotly
ggplotly(p)
#enjoy!