An Example of Plots in R

Author

Brenden Wheeler

Published

April 6, 2023

MTT Assay of RAW with DD-ITA

Below is a short demonstration of how R can create the same plots as GraphPad. The benefit of R is that the plots can be more easily adjust based on user needs. Some examples are changing colour palettes, adding layers to plots, grouping plots, etc.


Post-hoc Tests

Here is a short description between two common post-hoc tests following a statistically significant ANOVA.

Information was taken from wikipedia

Test statistic:

\(q_{s} = \frac{Y_{a}-Y_{b}}{SE}\)

Where: \(q_{s}\), is the studentized range distribution:

\(q = \frac{\bar{y}_{max}-\bar{y}_{min}}{S\sqrt{2/n}}\)

The method is as follows:

  • Suppose you have \(m\) p-values, sorted into order lowest-to-highest \(P_{1},…,P_{m}\) and their corresponding hypotheses \(H_{1},…,H_{m}\) (null hypotheses). You want the FWER to be no higher than a certain pre-specified \(\alpha\).

  • Is \(P_{1} < \alpha/m\)? If so, reject \(H_{1}\) and continue to the next step, otherwise EXIT.

  • Is \(P_{2}<α/(m-1)\)? If so, reject \(H_{2}\) also, and continue to the next step, otherwise EXIT.

  • And so on: for each P value, test whether \(P_{k} < \frac{\alpha}{m + 1 - k}\). If so, reject \(H_{k}\) and continue to examine the larger P values, otherwise EXIT.

This method ensures that the FWER is at most \(\alpha\), in the strong sense.

Table 1: Comparing Tukey to Multiple t-test
group1 group2 Mult t-test (Holm) Tukey HSD
5X Negative 0.00062 0.000001
5X Positive 0.00000 0.000000
10X Negative 0.01600 0.000951
10X Positive 0.00000 0.000000
25X Negative 0.67000 0.987000
25X Positive 0.00000 0.000000

Plotting in R - Boxplots, etc.

Tip

Expand the code to see the source code for generating a barplot using the ggpubr package.

Code
#Making the Barplot as shown below
#Initialize the library dependencies
library(tidyverse)
library(ggpubr)
library(rstatix)

#Create the bar plot
bp <- ggbarplot(
  data_small, x = "Sample", y = "abs", 
  color = "Sample",
  palette = "Okabe-Ito", 
  width = 0.7,
  size = 0.8,
  add = c("mean_sd", "jitter"),
  add.params = list(color="black"),
  title = "10 Day DD-ITA", 
  xlab = "", 
  ylab = "Absorbance (590nm)",
  legend.title = "",
  position = position_dodge(0.15),
  subtitle = "Adjusted p-values: p > 0.05 * | p <= 0.05 ** | p <= 0.01 *** | p <= 0.001 **** | p <= 0.0001",
  sort.by.groups = TRUE) + #this group thing is important
  theme(plot.title = element_text(size = 14, hjust= 0.5),
        plot.subtitle = element_text(size = 8, hjust= 0.5),
        axis.ticks.length = unit(0.15, "cm"),
        legend.position = "right"
  ) + 
  stat_pvalue_manual(
    stat.test, label = "{p.adj.signif}", tip.length = 0.01, hide.ns = TRUE,
    bracket.nudge.y = 0.05, step.increase = 0.03) +
  scale_y_continuous(expand = expansion(mult = c(0, 0.1)),
                     breaks = seq(from = 0, to= 0.5, by = 0.1))