spinToPlots | R Documentation |
Take anansi output and wrangle it to a list of plottable objects.
spinToPlots(
anansiYarn,
target = NULL,
translate = FALSE,
Y_translation = NULL,
X_translation = NULL
)
anansiYarn |
The output of the main anansi function. |
target |
A boolean matrix. Determines which associations should be prepared for plotting. Default is the dictionary. |
translate |
Boolean, default is FALSE Toggles whether to translate the names of the features in tableX and tableY to human readable names. |
Y_translation |
data.frame, a lookup table with featureY names as the first column and human readable names as the second. See |
X_translation |
data.frame, a lookup table with featureX names as the first column and human readable names as the second. See |
a list of ready to plot data.frames and their names.
# Starting off from the example in ?anansi
data(dictionary)
data(FMT_data)
# Clean and prepare the example data.
# In the example dataset, the metabolites are already cleaned.
KOs <- floor(FMT_KOs)
KOs <- apply(KOs, c(1, 2), function(x) as.numeric(as.character(x)))
KOs <- KOs[apply(KOs == 0, 1, sum) <= (ncol(KOs) * 0.90), ]
KOs.exp <- clr_c(KOs[row.names(KOs) %in% sort(unique(unlist(anansi_dic))), ])
t1 <- t(FMT_metab)
t2 <- t(KOs.exp)
# Run anansi pipeline.
web <- weaveWebFromTables(
tableY = t1,
tableX = t2,
dictionary = anansi_dic
)
anansi_out <- anansi(
web = web,
formula = ~Legend,
groups = "Legend",
metadata = FMT_metadata,
adjust.method = "BH",
verbose = TRUE
)
# Let's look at all canonical interactions that also have a sufficiently well-fitting model:
outPlots <- spinToPlots(anansi_out)
# load ggplot2 and patchwork for plotting
library(ggplot2)
library(patchwork)
plotted <- lapply(outPlots, FUN = function(p) {
# Main ggplot call
ggplot(data = p$data, aes(x = X, y = Y, fill = groups)) +
# Define geoms:
geom_point(shape = 21) +
geom_smooth(method = "lm") +
theme_bw() +
# Improve annotation:
scale_fill_manual(values = c(
"Young yFMT" = "#2166ac",
"Aged oFMT" = "#b2182b",
"Aged yFMT" = "#ef8a62"
)) +
ylab(p$name[1]) +
xlab(p$name[2]) +
ggtitle(paste(p$name[1], "vs", p$name[2]))
})
# Call patchwork to unify and arrange the first 6 plots
wrap_plots(plotted[1:6]) + plot_layout(guides = "collect")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.