plotMRF_hm: Plot MRF interaction parameters as a heatmap

View source: R/plotMRF_hm.R

plotMRF_hmR Documentation

Plot MRF interaction parameters as a heatmap

Description

This function uses outputs from fitted MRFcov and bootstrap_MRF models to plot a heatmap of node interaction coefficients.

Usage

plotMRF_hm(MRF_mod, node_names, main, plot_observed_vals, data)

Arguments

MRF_mod

A fitted MRFcov or bootstrap_MRF object

node_names

A character vector of species names for axis labels. Default is to use rownames from the MRFcov$graph slot

main

An optional character title for the plot

plot_observed_vals

Logical. If TRUE and the family of the fitted MRFcov model is 'binomial', then raw observed occurrence and co-occurrence values will be extracted from data and overlaid on the resulting heatmap. Note, this option is not available for bootstrap_MRF models

data

Optional dataframe containing the input data where the left-most columns represent binary occurrences of species that are represented by nodes in the graph. This call is only necessary if users wish to overlay raw observed occurrence and co-occurrence values on the heatmap of node interaction coefficients (only avaiable for family = 'binomial' models)

Details

Interaction parameters from MRF_mod are plotted as a heatmap, where red colours indicate positive interactions and blue indicate negative interactions. If plot_observed_vals == TRUE, raw observed values of single occurrences (on the diagonal) and co-occurrences for each species in data are overlaid on the plot (only avaiable for family = 'binomial' models). Note, this option is not available for bootstrap_MRF models

Value

A ggplot2 object

See Also

MRFcov bootstrap_MRF

Examples


data("Bird.parasites")
CRFmod <- MRFcov(data = Bird.parasites, n_nodes = 4, family = 'binomial')
plotMRF_hm(MRF_mod = CRFmod)
plotMRF_hm(MRF_mod = CRFmod, plot_observed_vals = TRUE, data = Bird.parasites)

#To plot as an igraph network instead, we can simply extract the adjacency matrix
net <- igraph::graph.adjacency(CRFmod$graph, weighted = TRUE, mode = "undirected")
igraph::plot.igraph(net, layout = igraph::layout.circle,
                   edge.width = abs(igraph::E(net)$weight),
                   edge.color = ifelse(igraph::E(net)$weight < 0, 'blue', 'red'))


nicholasjclark/MRFcov documentation built on March 30, 2024, 10:31 p.m.