run multi-way ANOVA and Tukey HSD

load packages and data

fix the data structure

str(CD_raw)                     # check 'Treatment' data type
## 'data.frame':    18 obs. of  2 variables:
##  $ Treatment: int  0 0 0 100 100 100 450 450 450 800 ...
##  $ Cells_cm2: int  24736 13157 17894 23947 2894 13421 27368 10263 18684 30789 ...
CD_raw$Treatment <-
    as.factor(CD_raw$Treatment) # convert the 'Treatment' column to a factor because it's categorical data

run the multi-way ANOVA

anova_result <- aov(Cells_cm2 ~ Treatment, data = CD_raw)

anova_result %>% tidy() %>% select(p.value) # select for p-value
## # A tibble: 2 × 1
##   p.value
##     <dbl>
## 1  0.0577
## 2 NA
# p-value > 0.05, no post-hoc test needed

create figure 3

calculate summary statistics

CD_summ <- CD_raw %>%             # assign summary statistics to a new data frame
    group_by(
        Treatment) %>%            # group data by G418 concentration
    summarize(                    # create new data frame by summarizing grouped data
        Mean = mean(Cells_cm2),   # calculate the average confluence
        Stdev = sd(Cells_cm2),    # calculate the standard deviation
        Low_CI = Mean - 2*Stdev,  # calculate the low confidence interval
        High_CI = Mean + 2*Stdev, # calculate the high confidence interval
    )

make a bar plot showing each treatment’s mean cell density on day 7

ggplot(                # create a plot using ggplot2
    data = CD_summ,    # use summarized cell density data
    aes(               # set plot aesthetics
        x = Treatment, # x-axis = treatment (G418 concentration)
        y = Mean       # y-axis = mean cell density
    )) +
  geom_bar(              # add bar geometries to the plot
      stat = "identity", # make each treatment use its associated cell density 
      fill = c(          # concatenate bar colors into a vector
          "tomato", "gold", "forestgreen", "darkturquoise", "blue3", "deeppink"),
      width = 0.8        # individual bar thickness
      ) +
  geom_errorbar(           # add error bars to the plot
      aes(                 # set error bar aesthetics
          ymin = Low_CI,   # assign low confidence interval to the error bars
          ymax = High_CI), # assign high confidence interval to the error bars
      width = 0.2          # thickness of error bars
      ) +
  labs(                    # change x and y-axis titles
      x = "G418 concentration", # label x-axis
      y = expression(      # label y-axis; create an expression to superscript
          paste(           # isolate "2" from expression to superscript, paste the closed bracket after it
              "Mean cell density (cells/cm"^"2", ")"
          ))) +
  theme(                                                    # change theme elements
      axis.title = element_text(size = 20),                 # x and y-axis text size
      axis.text = element_text(size = 16),                  # x and y tick mark text size
      axis.title.x = element_text(margin = margin(t = 15)), # x-axis title top margin
      axis.title.y = element_text(margin = margin(r = 15)), # y-axis title right margin
      axis.text.x = element_text(margin = margin(t = 10)),  # x-axis label top margin 
      axis.text.y = element_text(margin = margin(r = 10))   # y-axis label right margin
      ) +
    scale_x_discrete(                            # change x-axis aesthetics
        labels = paste(levels(CD_raw$Treatment), # paste "µg/ml" to the end of each x-axis label
                       "µg/ml")
        )