plotHeat | R Documentation |
A function to draw heatmaps with the option to use p-values
or significance codes as cell text. It allows to draw a mixed heatmap with
different cell text (values, p-values, or significance code) in the lower
and upper triangle. The function corrplot
is used
for plotting the heatmap.
plotHeat(
mat,
pmat = NULL,
type = "full",
textUpp = "mat",
textLow = "code",
methUpp = "color",
methLow = "color",
diag = TRUE,
title = "",
mar = c(0, 0, 1, 0),
labPos = "lt",
labCol = "gray40",
labCex = 1.1,
textCol = "black",
textCex = 1,
textFont = 1,
digits = 2L,
legendPos = "r",
colorPal = NULL,
addWhite = TRUE,
nCol = 51L,
colorLim = NULL,
revCol = FALSE,
color = NULL,
bg = "white",
argsUpp = NULL,
argsLow = NULL
)
mat |
numeric matrix with values to be plotted. |
pmat |
optional matrix with p-values. |
type |
character defining the type of the heatmap. Possible values are:
|
textUpp |
character specifying the cell text either for the
full heatmap (if
|
textLow |
same as |
methUpp |
character specifying how values are represented in the
full heatmap (if |
methLow |
same es |
diag |
logical. If |
title |
character giving the title. |
mar |
vector specifying the plot margins.
See |
labPos |
character defining the label position. Possible values are:
"lt"(left and top, default),
"ld"(left and diagonal; |
labCol |
label color. Default is "gray40". Passed to
|
labCex |
numeric defining the label size. Default is 1.1. Passed to
|
textCol |
color of the cell text (values, p-values, and code). Default is "black". |
textCex |
numeric defining the text size. Default is 1. Currently only works for types "mat" and "code". |
textFont |
numeric defining the text font. Default is 1. Currently only works for type "mat". |
digits |
integer defining the number of decimal places used for matrix values and p-values. |
legendPos |
position of the color legend. Possible values are: "r"(right; default), "b"(bottom), "n"(no legend). |
colorPal |
character specifying the color palette used for cell coloring
if
By default, "RdBu" is used if the first value of |
addWhite |
logical. If |
nCol |
integer defining the number of colors to which the color palette
should be interpolated. Default is 51L.
|
colorLim |
numeric vector with two values defining the color limits.
The first element of the color vector is assigned to the lower limit and
the last element of the color vector to the upper limit. Default is
c(0,1) if the values of |
revCol |
logical. If |
color |
an optional vector with colors used for cell coloring. |
bg |
background color of the cells. Default is "white". |
argsUpp |
optional list of arguments passed to
|
argsLow |
same as |
Invisible list with two elements argsUpper
and
argsLower
containing the corrplot
arguments used for the upper and lower triangle of the heatmap.
# Load data sets from American Gut Project (from SpiecEasi package)
data("amgut2.filt.phy")
# Split data into two groups: with and without seasonal allergies
amgut_season_yes <- phyloseq::subset_samples(amgut2.filt.phy,
SEASONAL_ALLERGIES == "yes")
amgut_season_no <- phyloseq::subset_samples(amgut2.filt.phy,
SEASONAL_ALLERGIES == "no")
# Sample sizes
phyloseq::nsamples(amgut_season_yes)
phyloseq::nsamples(amgut_season_no)
# Make sample sizes equal to ensure comparability
n_yes <- phyloseq::nsamples(amgut_season_yes)
amgut_season_no <- phyloseq::subset_samples(amgut_season_no, X.SampleID %in%
get_variable(amgut_season_no,
"X.SampleID")[1:n_yes])
# Network construction
amgut_net <- netConstruct(data = amgut_season_yes,
data2 = amgut_season_no,
measure = "pearson",
filtTax = "highestVar",
filtTaxPar = list(highestVar = 50),
zeroMethod = "pseudoZO",
normMethod = "clr",
sparsMethod = "thresh",
thresh = 0.4,
seed = 123456)
# Estimated and sparsified associations of group 1
plotHeat(amgut_net$assoEst1, textUpp = "none", labCex = 0.6)
plotHeat(amgut_net$assoMat1, textUpp = "none", labCex = 0.6)
# Compute graphlet correlation matrices and perform significance tests
adja1 <- amgut_net$adjaMat1
adja2 <- amgut_net$adjaMat2
gcm1 <- calcGCM(adja1)
gcm2 <- calcGCM(adja2)
gcmtest <- testGCM(obj1 = gcm1, obj2 = gcm2)
# Mixed heatmap of GCM1 and significance codes
plotHeat(mat = gcmtest$gcm1,
pmat = gcmtest$pAdjust1,
type = "mixed",
textLow = "code")
# Mixed heatmap of GCM2 and p-values (diagonal disabled)
plotHeat(mat = gcmtest$gcm1,
pmat = gcmtest$pAdjust1,
diag = FALSE,
type = "mixed",
textLow = "pmat")
# Mixed heatmap of differences (GCM1 - GCM2) and significance codes
plotHeat(mat = gcmtest$diff,
pmat = gcmtest$pAdjustDiff,
type = "mixed",
textLow = "code",
title = "Differences between GCMs (GCM1 - GCM2)",
mar = c(0, 0, 2, 0))
# Heatmap of differences (insignificant values are blank)
plotHeat(mat = gcmtest$diff,
pmat = gcmtest$pAdjustDiff,
type = "full",
textUpp = "sigmat")
# Same as before but with higher significance level
plotHeat(mat = gcmtest$diff,
pmat = gcmtest$pAdjustDiff,
type = "full",
textUpp = "sigmat",
argsUpp = list(sig.level = 0.1))
# Heatmap of absolute differences
# (different position of labels and legend)
plotHeat(mat = gcmtest$absDiff,
type = "full",
labPos = "d",
legendPos = "b")
# Mixed heatmap of absolute differences
# (different methods, text options, and color palette)
plotHeat(mat = gcmtest$absDiff,
type = "mixed",
textLow = "mat",
methUpp = "number",
methLow = "circle",
labCol = "black",
textCol = "gray50",
textCex = 1.3,
textFont = 2,
digits = 1L,
colorLim = range(gcmtest$absDiff),
colorPal = "Blues",
nCol = 21L,
bg = "darkorange",
addWhite = FALSE)
# Mixed heatmap of differences
# (different methods, text options, and color palette)
plotHeat(mat = gcmtest$diff,
type = "mixed",
textLow = "none",
methUpp = "number",
methLow = "pie",
textCex = 1.3,
textFont = 2,
digits = 1L,
colorLim = range(gcmtest$diff),
colorPal = "PiYG",
nCol = 21L,
bg = "gray80")
# Heatmap of differences with given color vector
plotHeat(mat = gcmtest$diff,
nCol = 21L,
color = grDevices::colorRampPalette(c("blue", "white", "orange"))(31))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.