Learn R Programming

rtpcr (version 2.1.3)

plotFactor: Bar plot of gene expression for 1-, 2-, or 3-factor experiments

Description

Creates a bar plot of relative gene expression (fold change) values from 1-, 2-, or 3-factor experiments, including error bars and statistical significance annotations.

Usage

plotFactor(
  data,
  x_col,
  y_col,
  Lower.se_col,
  Upper.se_col,
  group_col = NULL,
  facet_col = NULL,
  letters_col = NULL,
  letters_d = 0.2,
  col_width = 0.8,
  err_width = 0.15,
  dodge_width = 0.8,
  fill_colors = NULL,
  color = "black",
  alpha = 1,
  base_size = 12,
  legend_position = "right",
  ...
)

Value

ggplot2 plot object

Arguments

data

Data frame containing expression results

x_col

Character. Column name for x-axis

y_col

Character. Column name for bar height

Lower.se_col

Character. Column name for lower SE

Upper.se_col

Character. Column name for upper SE

group_col

Character. Column name for grouping bars (optional)

facet_col

Character. Column name for faceting (optional)

letters_col

Character. Column name for significance letters (optional)

letters_d

Numeric. Vertical offset for letters (default 0.2)

col_width

Numeric. Width of bars (default 0.8)

err_width

Numeric. Width of error bars (default 0.15)

dodge_width

Numeric. Width of dodge for grouped bars (default 0.8)

fill_colors

Optional vector of fill colors to change the default colors

color

Optional color for the bar outline

alpha

Numeric. Transparency of bars (default 1)

base_size

Numeric. Base font size for theme (default 12)

legend_position

Character or numeric vector. Legend position (default right)

...

Additional ggplot2 layer arguments

Author

Ghader Mirzaghaderi

Examples

Run this code
data <- read.csv(system.file("extdata", "data_2factorBlock3ref.csv", package = "rtpcr"))

res <- ANOVA_DDCt(x = data,
  numOfFactors = 2,
  numberOfrefGenes = 3,
  block = "block",
  mainFactor.column = 2,
  p.adj = "none")

df <- res$relativeExpression

p1 <- plotFactor(
  data = df,
  x_col = "contrast",
  y_col = "RE",
  group_col = "gene",
  facet_col = "gene",
  Lower.se_col = "Lower.se.RE",
  Upper.se_col = "Upper.se.RE",
  letters_col = "sig",
  letters_d = 0.2,
  alpha = 1,
  col_width = 0.7,
  dodge_width = 0.7,
  base_size = 14, 
  legend_position = "none")

p1


data2 <- read.csv(system.file("extdata", "data_3factor.csv", package = "rtpcr"))
#Perform analysis first
res <- ANOVA_DCt(
  data2,
  numOfFactors = 3,
  numberOfrefGenes = 1,
  block = NULL)
  
df <- res$relativeExpression
# Generate three-factor bar plot
 p <- plotFactor(
  df,
  x_col = "SA",       
  y_col = "log2FC",       
  group_col = "Type",   
  facet_col = "Conc",    
  Lower.se_col = "Lower.se.log2FC",
  Upper.se_col = "Upper.se.log2FC",
  letters_col = "sig",
  letters_d = 0.3,
  col_width = 0.7, 
  dodge_width = 0.7,
  #fill_colors = c("blue", "brown"),
  color = "black",
  base_size = 14, 
  alpha = 1,
  legend_position = c(0.1, 0.2))
p
  

Run the code above in your browser using DataLab