gg4way 1.5.0
4way plots enable a comparison of the logFC values from two contrasts of differential gene expression (Friedman and Maniatis 2011). The gg4way package creates 4way plots using the ggplot2 framework and supports popular Bioconductor objects. The package also provides information about the correlation between contrasts and significant genes of interest.
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install("gg4way")
To install the development version directly from GitHub:
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
remotes::install_github("ben-laufer/gg4way")
This example involves testing a popular RNA-seq dataset using limma-voom.
First the airway data package is loaded, gene symbols are added, and then for the purpose of this vignette only genes with symbols are kept.
library("airway")
data("airway")
se <- airway
library("org.Hs.eg.db")
rowData(se)$symbol <- mapIds(org.Hs.eg.db,
keys = rownames(se),
column = "SYMBOL",
keytype = "ENSEMBL")
rowData(se)$ID <- rownames(se)
se <- se[!is.na(rowData(se)$symbol)]
The output from limma::eBayes()
and limma::treat()
is supported; however, only the former is shown for this example.
library("edgeR")
library("limma")
dge <- se |>
SE2DGEList()
design <- model.matrix(~ 0 + cell + dex, data = dge$samples)
colnames(design) <- gsub("cell", "", colnames(design))
contr.matrix <- makeContrasts(N61311 - N052611,
N061011 - N052611,
levels = c("N052611", "N061011",
"N080611", "N61311",
"dexuntrt"))
keep <- filterByExpr(dge, design)
dge <- dge[keep, ]
efit <- dge |>
calcNormFactors() |>
voom(design) |>
lmFit(design) |>
contrasts.fit(contrasts = contr.matrix) |>
eBayes()
Finally, we create a 4way plot comparing the logFC for all genes in the two contrasts.
library("gg4way")
p1 <- efit |>
gg4way(x = "N61311 vs N052611",
y = "N061011 vs N052611")
p1
The legend title at the bottom shows that there is a correlation of r = 0.43, which is exemplified by more shared DEGs (blue dots) going in the same direction (upper right and bottom left) than opposite direction (upper left and bottom right). The numbers in the plot give the totals for the different quadrants of the 4way plot. If you look at the bottom left quadrant, the blue text shows that there are 62 DEGs where N052611 has significantly increased expression relative to both N61311 and N061011. The red text shows that there are 238 DEGs where N052611 has significantly increased expression relative to N61311 only, while the green text shows that there are 41 DEGs where N052611 has significantly increased expression relative to N061011 only.
The genes that are significant in both contrasts can be obtained in a table through getShared()
.
p1 |>
getShared() |>
head()
## # A tibble: 6 × 12
## ID symbol `N61311 vs N052611 LogFC` `N061011 vs N052611 LogFC`
## <chr> <chr> <dbl> <dbl>
## 1 ENSG00000204941 PSG5 -4.61 -5.24
## 2 ENSG00000164308 ERAP2 3.45 3.77
## 3 ENSG00000018625 ATP1A2 -2.81 -2.17
## 4 ENSG00000262902 MTCO1P40 -6.72 -6.78
## 5 ENSG00000180914 OXTR -3.78 -3.18
## 6 ENSG00000078018 MAP2 -3.10 -1.35
## # ℹ 8 more variables: `N61311 vs N052611 FDR` <dbl>,
## # `N061011 vs N052611 FDR` <dbl>, `N61311 vs N052611 FDRpass` <lgl>,
## # `N061011 vs N052611 FDRpass` <lgl>, `N61311 vs N052611 Direction` <chr>,
## # `N061011 vs N052611 Direction` <chr>, Significant <fct>, alpha <dbl>
Gene symbols can be added to the plot through the label
argument. Setting it to TRUE
will plot all the genes colored blue, while specific genes can be labelled by providing their symbol. Below, two of the genes from the above table are labelled in the plot.
efit |>
gg4way(x = "N61311 vs N052611",
y = "N061011 vs N052611",
label = c("PSG5", "ERAP2"))