Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. grid_arrange_shared_legend <- function(...) {
  2. plots <- list(...)
  3. g <- ggplotGrob(plots[[1]] + theme(legend.position = "bottom"))$grobs
  4. legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
  5. lheight <- sum(legend$height)
  6. grid.arrange(
  7. do.call(arrangeGrob, lapply(plots, function(x)
  8. x + theme(legend.position="none"))),
  9. legend,
  10. ncol = 1,
  11. heights = unit.c(unit(1, "npc") - lheight, lheight))
  12. }
  13.  
  14. data = read.table("fermentation_run.csv", header=TRUE, sep=",", fileEncoding="UTF-8-BOM")
  15. p1 <- ggplot(data, aes(x = time)) +
  16. geom_line(aes(y = cdw*5, colour = "CDW"), size=1) +
  17. geom_line(aes(y = glucose, colour = "glucose"), size=1) +
  18. geom_step(aes(y = substrate, colour = "substrate"), size=1) +
  19. theme_classic() + ylab("Concentration (g/l)") +
  20. xlab("Time (h)") +
  21. scale_colour_manual(values = c("grey", "red", "black"))
  22. theme(legend.position="bottom", legend.title=element_blank())
  23.  
  24. p2 <- ggplot(data, aes(x=time)) +
  25. geom_line(aes(y = alkyl, colour = "alkyl SS"), size=1) +
  26. geom_line(aes(y = oleyl, colour = "oleyl alcohol"), size=1) +
  27. theme_classic() +
  28. xlab("Time (h)") +
  29. ylab("Concentration (g/l)") +
  30. scale_colour_manual(values = c("green", "blue"))
  31. theme(legend.position="bottom", legend.title=element_blank())
  32.  
  33. p3 <- ggplot(data, aes(x=time)) +
  34. geom_step(aes(y = aeration, colour="aeration"), size=1) +
  35. geom_line(aes(y = do/2, colour="dissolved oxygen"), size=1) +
  36. theme_classic() +
  37. xlab("Time (h)") +
  38. ylab("Aeration (lpm)") +
  39. scale_y_continuous(sec.axis = sec_axis(~.*2, name = "Dissolved oxygen (%)")) +
  40. theme(legend.position="bottom", legend.title=element_blank())
  41.  
  42. grid_arrange_shared_legend(p1, p2,p3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement