This notebook provides a simple example of how one can create barplots easily from FCirc data exported from TraceBase.

First, we load our required libraries.

# Load required libraries
library(readr, quietly = TRUE)
library(ggplot2, quietly = TRUE)
library(Rmisc, quietly = TRUE)
library(dplyr, quietly = TRUE)

Glucose Ra (Fcirc) - Serine Sythesis Study

Load Fcirc data

The PeakGroup data was downloaded from TraceBase by:

  1. View a specific study^
  2. Click the “FCirc Data” link at the top
  3. Click on the “Export Data” button

^ The study data used in this example (Serine synthesis from glucose in control vs ser/gly-free diet) is not publicly available, but by following this example, you can apply a similar analysis to any of the Studies available on tracebase.princeton.edu.

serinesyn_fcirc_data_table <-
  "data/serine_synthesis/Fcirc_10.02.2023.16.29.36.tsv"
serinesyn_fcirc_data <-
  readr::read_tsv(serinesyn_fcirc_data_table, comment = "#")
## Rows: 21 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: "\t"
## chr (10): Animal, Studies, Genotype, Age (weeks), Sex, Diet, Feeding Status,...
## dbl (12): Body Weight (g), Infusion Rate (ul/min/g), Tracer Concentration (m...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
serinesyn_fcirc_data

Plot average Ra by tracer compound

For this example, we are going to plot the average “Rate of Appearance (Ra)” for glucose, split by “Feeding Status”.

Select data

First, we select the columns we want from the data

serinesyn_fcirc_plot_data <- serinesyn_fcirc_data %>%
  # Select maximum time collected for each animal
  group_by(Animal) %>%
  slice(which.max(`Time Collected (m)`))

Calculate summary statistics

We use the summarySE function to calculate the average along with the standard deviation (sd), standard error (se), and confidence interval (ci).

serinesyn_fcirc_summary_data <- serinesyn_fcirc_plot_data %>%
  Rmisc::summarySE(
    measurevar = "Average Ra (nmol/min/g)",
    groupvars = c("`Tracer Compound`", "`Feeding Status`")
  )
serinesyn_fcirc_summary_data

Generate the bar plot

Now we setup the plotting parameters. Note we use standard deviation here for the error bars, but you are free to use whichever statistic is most appropriate.

# Setup the plot
serinesyn_fcirc_plot <- ggplot(
  data = serinesyn_fcirc_summary_data,
  aes(
    x = `Tracer Compound`,
    y = `Average Ra (nmol/min/g)`,
    fill = `Feeding Status`
  )
) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(
    ymin = `Average Ra (nmol/min/g)` - sd,
    ymax = `Average Ra (nmol/min/g)` + sd
  ),
  width = .2,
  position = position_dodge(.9)
  ) +
  ggtitle("Glucose Average Rate of Appearance (Fcirc) - Serine Synthesis Study")

# Display the plot
serinesyn_fcirc_plot

Glucose Ra (Fcirc) - Multiple Studies

Load Fcirc data

The Fcirc data was downloaded from TraceBase by using the Advanced Search, selecting the “Fcirc” Output Format, and matching on “glucose” as the Tracer Compound.

Fcirc Glucose Tracer Search
Fcirc Glucose Tracer Search
glucose_fcirc_data_table <-
  "data/Fcirc-glucose-all-studies_10.02.2023.16.32.27.tsv"
glucose_fcirc_data <- readr::read_tsv(glucose_fcirc_data_table,
  comment = "#",
  na = c("", "NA", "None")
)
## Rows: 158 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: "\t"
## chr  (9): Animal, Studies, Genotype, Sex, Diet, Feeding Status, Treatment, T...
## dbl (13): Body Weight (g), Age (weeks), Infusion Rate (ul/min/g), Tracer Con...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glucose_fcirc_data

Plot average Ra by tracer compound

For this example, we are going to plot the average “Rate of Appearance (Ra)” for glucose, split by “Feeding Status” and “Study”.

Select data

First, we select the columns we want from the data

glucose_fcirc_plot_data <- glucose_fcirc_data %>%
  # Select maximum time collected for each animal
  group_by(Animal) %>%
  slice(which.max(`Time Collected (m)`))

Calculate summary statistics

We use the summarySE function to calculate the standard error.

glucose_fcirc_summary_data <- glucose_fcirc_plot_data %>%
  Rmisc::summarySE(
    measurevar = "Average Ra (nmol/min/g)",
    groupvars = c("Studies", "`Feeding Status`"),
    na.rm = TRUE
  ) %>%
  # Rename some studies
  mutate(Studies = recode(Studies,
    "fluxomics 2020" = "Fluxomics 2020",
    "Serine synthesis from glucose in control vs ser/gly-free diet" =
      "Serine synthesis"
  ))
glucose_fcirc_summary_data

Generate the bar plot

Now we setup the plotting parameters.

# Setup the plot
glucose_fcirc_plot <- ggplot(
  data = glucose_fcirc_summary_data,
  aes(
    x = Studies,
    y = `Average Ra (nmol/min/g)`,
    fill = `Feeding Status`
  )
) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(
    ymin = `Average Ra (nmol/min/g)` - sd,
    ymax = `Average Ra (nmol/min/g)` + sd
  ),
  width = .2,
  position = position_dodge(.9)
  ) +
  ggtitle("Glucose Average Rate of Appearance (Fcirc)")

# Display the plot
glucose_fcirc_plot

Glucose Ra Over Time - Serine Synthesis Study

Calculate summary statistics

For this example, we are going to plot the average “Rate of Appearance (Ra)” for glucose over time, split by “Feeding Status”.

Calculate summary statistics

We use the summarySE function to calculate the standard error.

serinesyn_ratime_summary_data <- serinesyn_fcirc_data %>%
  # Change Time Collected to a factor (not a number)
  mutate_at(vars(`Time Collected (m)`), list(factor)) %>%
  Rmisc::summarySE(
    measurevar = "Average Ra (nmol/min/g)",
    groupvars = c("`Time Collected (m)`", "`Feeding Status`")
  )
serinesyn_ratime_summary_data

Generate the plot

Now we setup the plotting parameters.

# Setup the plot
serinesyn_ratime_plot <- ggplot(
  data = serinesyn_ratime_summary_data,
  aes(
    x = `Feeding Status`,
    y = `Average Ra (nmol/min/g)`,
    fill = `Time Collected (m)`
  )
) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(
    ymin = `Average Ra (nmol/min/g)` - sd,
    ymax = `Average Ra (nmol/min/g)` + sd
  ),
  width = .2,
  position = position_dodge(.9)
  ) +
  ggtitle("Glucose Ra over time - Serine Synthesis Study")

# Display the plot
serinesyn_ratime_plot