Plot a Heatmap of Correlations Between Module Eigennodes and Traits
Source:R/Explore_Module_Trait_Correlations.R
plotMEtraitCor.Rd
plotMEtraitCor()
takes a data.frame
of correlation statistics
for module eigennodes and traits from getMEtraitCor()
, plots it as a
heatmap, and saves it as a .pdf.
Usage
plotMEtraitCor(
MEtraitCor,
moduleOrder = 1:length(unique(MEtraitCor$module)),
traitOrder = 1:length(unique(MEtraitCor$trait)),
topOnly = FALSE,
nTop = 15,
p = 0.05,
label.type = c("star", "p"),
label.size = 8,
label.nudge_y = -0.38,
colors = blueWhiteRed(100, gamma = 0.9),
limit = NULL,
axis.text.size = 12,
legend.position = c(1.08, 0.915),
legend.text.size = 12,
legend.title.size = 16,
colColorMargins = c(-0.7, 4.21, 1.2, 11.07),
save = TRUE,
file = "ME_Trait_Correlation_Heatmap.pdf",
width = 11,
height = 9.5,
verbose = TRUE
)
Arguments
- MEtraitCor
A
data.frame
of correlation statistics for module-trait pairs, typically generated bygetMEtraitCor()
.- moduleOrder
A
numeric
specifying the order of modules in the heatmap. This must be the same length as the number of unique modules inMEtraitCor
.- traitOrder
A
numeric
specifying the order of traits in the heatmap. This must be the same length as the number of unique traits inMEtraitCor
.- topOnly
A
logical(1)
indicating whether to plot only modules and traits with the most significant correlations, ranked by p-value.- nTop
A
numeric(1)
specifying the number of top module-trait associations to include.- p
A
numeric(1)
giving the threshold for the p-value to assign a significant correlation.- label.type
A
character(1)
giving the type of label (star or p) to use to annotate significant correlations.- label.size
A
numeric(1)
specifying the size of the label text for annotating significant correlations.- label.nudge_y
A
numeric(1)
giving the amount to adjust the position of the label text on the y-axis.- colors
A
character
giving a vector of colors to use for the gradient on the heatmap. The default usesWGCNA::blueWhiteRed()
to generate these colors.- limit
A
numeric(1)
giving the maximum value (symmetric) for the heatmap color scale.- axis.text.size
A
numeric(1)
specifying the size of the text for the y-axis.- legend.position
A
numeric(2)
with the position of the legend, as x-axis, y-axis. May also be acharacter(1)
indicating "none", "left", "right", "bottom", or "top".- legend.text.size
A
numeric(1)
specifying the size of the text for the legend axis.- legend.title.size
A
numeric(1)
giving the size of the text for the legend title.- colColorMargins
A
numeric(4)
giving the width of the margins for the column (horizontal) color bar as top, right, bottom, and left.- save
A
logical(1)
indicating whether to save the plot.- file
A
character(1)
giving the file name (.pdf) for the saved plot.- width
A
numeric(1)
specifying the width in inches of the saved plot.- height
A
numeric(1)
specifying the height in inches of the saved plot.- verbose
A
logical(1)
indicating whether messages should be printed.
Details
plotMEtraitCor()
is designed to be used in combination with
getMEtraitCor()
. Stars or p-values are used to annotate significant
correlations, as defined by the p-value threshold. The heatmap can optionally
be filtered to include only modules and traits with the most significant
associations, ranked by p-value. A ggplot
object is produced and can
be edited outside of this function if desired.
See also
getModules()
to build a comethylation network and identify modules of comethylated regions.getMEtraitCor()
to calculate ME-trait correlations.getCor()
to calculate correlation coefficients.getDendro()
andplotDendro()
to generate and visualize dendrograms.
Examples
if (FALSE) {
# Get Comethylation Modules
modules <- getModules(methAdj, power = sft$powerEstimate, regions = regions,
corType = "pearson", file = "Modules.rds")
# Test Correlations between Module Eigennodes and Sample Traits
MEs <- modules$MEs
MEtraitCor <- getMEtraitCor(MEs, colData = colData, corType = "bicor",
file = "ME_Trait_Correlation_Stats.txt")
# Compare Top PCs to Sample Traits
MEtraitCor <- getMEtraitCor(PCs, colData = colData, corType = "bicor",
file = "PC_Trait_Correlation_Stats.txt")
PCdendro <- getDendro(PCs, distance = "bicor")
PCtraitDendro <- getCor(PCs, y = colData, corType = "bicor", robustY = FALSE) %>%
getDendro(transpose = TRUE)
plotMEtraitCor(PCtraitCor, moduleOrder = PCdendro$order,
traitOrder = PCtraitDendro$order,
file = "PC_Trait_Correlation_Heatmap.pdf")
# Examine Correlations between Sample Traits
traitDendro <- getCor(MEs, y = colData, corType = "bicor",
robustY = FALSE) %>%
getDendro(transpose = TRUE)
plotDendro(traitDendro, labelSize = 3.5, expandY = c(0.65,0.08),
file = "Trait_Dendrogram.pdf")
# Visualize Correlations between Module Eigennodes and Sample Traits
moduleDendro <- getDendro(MEs, distance = "bicor")
plotMEtraitCor(MEtraitCor, moduleOrder = moduleDendro$order,
traitOrder = traitDendro$order,
file = "ME_Trait_Correlation_Heatmap.pdf")
plotMEtraitCor(MEtraitCor, moduleOrder = moduleDendro$order,
traitOrder = traitDendro$order, topOnly = TRUE,
label.type = "p", label.size = 4, label.nudge_y = 0,
legend.position = c(1.11, 0.795),
colColorMargins = c(-1,4.75,0.5,10.1),
file = "Top_ME_Trait_Correlation_Heatmap.pdf", width = 8.5,
height = 4.25)
}