Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grid_arrange_shared_legend <- function(...) {
- plots <- list(...)
- g <- ggplotGrob(plots[[1]] + theme(legend.position = "bottom"))$grobs
- legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
- lheight <- sum(legend$height)
- grid.arrange(
- do.call(arrangeGrob, lapply(plots, function(x)
- x + theme(legend.position="none"))),
- legend,
- ncol = 1,
- heights = unit.c(unit(1, "npc") - lheight, lheight))
- }
- data = read.table("fermentation_run.csv", header=TRUE, sep=",", fileEncoding="UTF-8-BOM")
- p1 <- ggplot(data, aes(x = time)) +
- geom_line(aes(y = cdw*5, colour = "CDW"), size=1) +
- geom_line(aes(y = glucose, colour = "glucose"), size=1) +
- geom_step(aes(y = substrate, colour = "substrate"), size=1) +
- theme_classic() + ylab("Concentration (g/l)") +
- xlab("Time (h)") +
- scale_colour_manual(values = c("grey", "red", "black"))
- theme(legend.position="bottom", legend.title=element_blank())
- p2 <- ggplot(data, aes(x=time)) +
- geom_line(aes(y = alkyl, colour = "alkyl SS"), size=1) +
- geom_line(aes(y = oleyl, colour = "oleyl alcohol"), size=1) +
- theme_classic() +
- xlab("Time (h)") +
- ylab("Concentration (g/l)") +
- scale_colour_manual(values = c("green", "blue"))
- theme(legend.position="bottom", legend.title=element_blank())
- p3 <- ggplot(data, aes(x=time)) +
- geom_step(aes(y = aeration, colour="aeration"), size=1) +
- geom_line(aes(y = do/2, colour="dissolved oxygen"), size=1) +
- theme_classic() +
- xlab("Time (h)") +
- ylab("Aeration (lpm)") +
- scale_y_continuous(sec.axis = sec_axis(~.*2, name = "Dissolved oxygen (%)")) +
- theme(legend.position="bottom", legend.title=element_blank())
- grid_arrange_shared_legend(p1, p2,p3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement