Tutorial - Plotting data from cultures

1 Aim

This tutorial explain how plot growth curves for phytoplankton cultures in different conditions. * Antibiotics treatment : 4 RCC cultures, 8 days, 2 antibiotics, 5 concentrations,

2 Downloads

Install the following software :

install.packages("dplyr")     # To manipulate dataframes
install.packages("tidyr")     # To manipulate dataframes

install.packages("stringr")   # To strings

install.packages("ggplot2")   # for high quality graphics
install.packages("gridExtra") # for grids

install.packages("plotrix" )  # needed for standard error

3 Data used

  • cultures antibiotics.txt contains data obtained by Priscilla Gourvil on antibiotics treatment of RCC strains
  • grazing experiment.xlsx contains data obtained by Valeria Jimenez on grazing experiment on Micromonas

4 Tutorial description

4.1 Load the libraries

library("ggplot2")
library("gridExtra")
library("plotrix")  # needed for standard error
library("dplyr")
library("tidyr")
library("stringr")
library("readxl")

4.2 Antibiotics treatments

4.2.1 Read and reformat the data

Read the data

cell <- read.table("cultures antibiotics.txt", header = TRUE, sep = "\t", na.strings = "NA", 
    dec = ".", strip.white = TRUE)
knitr::kable(head(cell))
RCC Antibio Well Concentration X1 X2 X3 X4 X5 X6 X7
RCC 96 G 418 A01 0.5 35888 17043 3853 593 225 675 591
RCC 96 G 418 A02 0.5 27281 20952 337 450 84 394 562
RCC 96 G 418 A03 0.5 29952 19630 34846 3853 21318 19996 31639
RCC 96 G 418 B01 1.0 33018 17268 6468 337 478 394 253
RCC 96 G 418 B02 1.0 26662 20530 34902 675 22555 8268 14062
RCC 96 G 418 B03 1.0 24946 19040 49011 4725 21599 26746 277217

Change from wide format to long format

cell <- gather(cell, X1:X7, key = "day", value = "cell_number")
knitr::kable(head(cell))
RCC Antibio Well Concentration day cell_number
RCC 96 G 418 A01 0.5 X1 35888
RCC 96 G 418 A02 0.5 X1 27281
RCC 96 G 418 A03 0.5 X1 29952
RCC 96 G 418 B01 1.0 X1 33018
RCC 96 G 418 B02 1.0 X1 26662
RCC 96 G 418 B03 1.0 X1 24946

Reformat day as numeric

cell$day <- as.numeric(str_replace(cell$day, "X", ""))
knitr::kable(head(cell))
RCC Antibio Well Concentration day cell_number
RCC 96 G 418 A01 0.5 1 35888
RCC 96 G 418 A02 0.5 1 27281
RCC 96 G 418 A03 0.5 1 29952
RCC 96 G 418 B01 1.0 1 33018
RCC 96 G 418 B02 1.0 1 26662
RCC 96 G 418 B03 1.0 1 24946

Reformat concentration as character

cell$Concentration <- as.character(cell$Concentration)
knitr::kable(head(cell))
RCC Antibio Well Concentration day cell_number
RCC 96 G 418 A01 0.5 1 35888
RCC 96 G 418 A02 0.5 1 27281
RCC 96 G 418 A03 0.5 1 29952
RCC 96 G 418 B01 1 1 33018
RCC 96 G 418 B02 1 1 26662
RCC 96 G 418 B03 1 1 24946

Compute mean and SD for each RCC, Antibio, Concentration and day using dplyr

cell_1 <- cell %>% group_by(RCC, Antibio, Concentration, day) %>% summarise(cell_mean = mean(cell_number), 
    cell_sd = sd(cell_number), cell_se = std.error(cell_number))
knitr::kable(head(cell_1))
RCC Antibio Concentration day cell_mean cell_sd cell_se
RCC 4094 G 418 0.5 1 188562.333 46983.373 27125.863
RCC 4094 G 418 0.5 2 100846.333 48010.521 27718.887
RCC 4094 G 418 0.5 3 4087.667 3401.215 1963.692
RCC 4094 G 418 0.5 4 42195.333 18511.363 10687.541
RCC 4094 G 418 0.5 5 8727.667 14751.465 8516.763
RCC 4094 G 418 0.5 6 3806.000 6105.543 3525.037

4.2.2 Define graphics options

Define the color, line type and symbol shape

Concentration_color <- c(`0.2` = "white", `0.5` = "white", `0.8` = "white", 
    `1` = "black", `1.5` = "black", `2` = "black")
Concentration_linetype <- c(`0.2` = 1, `0.5` = 1, `0.8` = 1, `1` = 2, `1.5` = 2, 
    `2` = 2)
Concentration_shape <- c(`0.2` = 21, `0.5` = 22, `0.8` = 21, `1` = 22, `1.5` = 21, 
    `2` = 22)

Define graphics options

scaling_factor = 15
cell_label <- expression(paste("cell.", mL^-1))
cell_breaks = c(100, 1000, 10000, 1e+05, 1e+06)
x_max = 8
x_breaks = c(0, 2, 4, 6, 8)
x_labels = c("0", "2", "4", "6", "8")

4.2.3 Plot the data

plot1 <- ggplot(cell_1, aes(x = day, y = cell_mean, group = Concentration, xmin = 0, 
    xmax = x_max, shape = Concentration, fill = Concentration, linetype = Concentration)) + 
    facet_wrap(~RCC + Antibio, nrow = 4, ncol = 2, scales = "free") + geom_line(size = 0.8, 
    colour = "black") + geom_point(size = 4) + geom_errorbar(aes(ymin = cell_mean - 
    cell_se, ymax = cell_mean + cell_se), width = 0.2, linetype = 1) + theme_bw(scaling_factor) + 
    theme(panel.border = element_rect(colour = "black"), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), 
        legend.title = element_text(size = scaling_factor), legend.key = element_blank(), 
        axis.title = element_text(size = scaling_factor), legend.text = element_text(size = scaling_factor), 
        legend.key.height = unit(1, "cm"), axis.text = element_text(size = 0.8 * 
            scaling_factor), panel.background = element_rect(fill = "white")) + 
    theme(legend.position = "top", legend.box = "horizontal") + labs(x = "Days", 
    y = cell_label) + scale_x_continuous(breaks = x_breaks, labels = x_labels) + 
    scale_y_log10(breaks = cell_breaks, labels = scales::trans_format("log10", 
        scales::math_format(10^.x))) + annotation_logticks(sides = "lr") + scale_fill_manual(values = Concentration_color) + 
    scale_shape_manual(values = Concentration_shape) + scale_linetype_manual(values = Concentration_linetype)

# Add next line to zoom + coord_cartesian(ylim=c(100, 10000000))

plot1

# Next can be used to save the plot as pdf ggsave(file='Fig 1 version
# 2.0.pdf', plot=plot1, scale=5, width = 7, height = 10, units = 'cm',
# useDingbats=FALSE)

4.3 Grazing experiment

Micromonas are fed with fluorescent labelled beads and one looks at the % of cells that have beads The idea is to do a plot with 2 different scales for the y axis.

4.3.0.1 Read the data

grazing <- read_xlsx("grazing experiment.xlsx", sheet = "RCC2306")

# Compute a new variable with the same scale as the cell concentration to be
# able to plot on the same graph
grazing$cell_beads_pct_scaled <- grazing$cell_beads_pct * 2e+05

knitr::kable(head(grazing))
species RCC# exp treatment time pnt time rep Well Date allPhyto.Count PhytoBeads.Count Total Volume (µL) cell_ml PhytoBeads per ml cell_beads_pct cell_beads_pct_scaled
M. polaris 2306 4 Light 100%L1ASW T0 0 A A09 02.23.2018 17192 848 124.6178 1379578 68048 4.93 986000
M. polaris 2306 4 Light 100%L1ASW T0 0 B A10 02.23.2018 17955 808 124.6240 1440734 64835 4.50 900000
M. polaris 2306 4 Dark 100%L1ASW T0 0 A A11 02.23.2018 13898 602 124.6236 1115198 48305 4.33 866000
M. polaris 2306 4 Dark 100%L1ASW T0 0 B A12 02.23.2018 14525 685 124.6233 1165512 54966 4.72 944000
M. polaris 2306 4 Light 100%L1ASW T3 3 A C09 02.23.2018 19589 753 124.6257 1571827 60421 3.84 768000
M. polaris 2306 4 Light 100%L1ASW T3 3 B C10 02.23.2018 19383 818 124.6240 1555318 65637 4.22 844000

4.3.0.2 Plot the data

Demonstrate the use of sec_axis.

plot <- ggplot(data = grazing, aes(x = time, y = cell_ml, ymin = 0, fill = treatment)) + 
    geom_point(size = 4, shape = 21) + labs(x = "Time (hours)", y = "Cells per mL - circles") + 
    geom_point(size = 4, shape = 22, aes(x = time, y = cell_beads_pct_scaled, 
        fill = treatment)) + scale_y_continuous(sec.axis = sec_axis(~./2e+05, 
    name = "% of cells with beads - squares"))
print(plot)

Daniel Vaulot

04 05 2018