plot_compar: Plot and Save Comparison Figures Between Pairs of Graphs

View source: R/plot_compar.R

plot_comparR Documentation

Plot and Save Comparison Figures Between Pairs of Graphs

Description

Given a list of pairwise graph comparisons, the function plots any given subset selected by graph name, displaying side-by-side pairs of graphs and highlighting common nodes or common edges with a choice of several graphical parameters.

Usage

plot_compar(
  listg,
  dec2comp = NULL,
  focus = "nodes",
  dir = getwd(),
  nd.color = c("orange", "red"),
  nd.size = c(0.5, 1),
  ed.color = c("orange", "red"),
  ed.width = c(1, 2),
  lbl.size = 0.5,
  dir.out = dir,
  out.file.name = NULL,
  img.format = NULL,
  res = 300
)

Arguments

listg

a list of graph pairwise comparisons as returned by list_compar.

dec2comp

a vector with the names of the graphs for which comparisons are to be plotted. The user can select to plot all pairwise combinations (by default), all combinations of a subset, or a single pair.

focus

either "nodes" (default) or "edges". It selects the type of comparison to be plotted, highlighting common nodes or common edges, respectively.

dir

Data folder including the decoration images. By default the working directory.

nd.color, nd.size, ed.color, ed.width

graphical parameters for color and size/widths of nodes and edges. Each of them is a vector with two values for different and common nodes/edges, respectively. If only one value is provided, this unique value is taken for both different and common elements. Labels are displayed with the same color as common nodes. For focus = "nodes" all edges are plotted with the first value of ed.color and ed.width.

lbl.size

graphical parameter for the size of the labels with the node names. The default is 0.5.

dir.out

folder for the output image. By default, it coincides with the input dir.

out.file.name

name of the output image, including path from current directory and extension. By default the name is automatically generated including site,decor, nd.var, and the extension from img.format. If set, out.file.name overrides dir.out and img.format.

img.format, res

format and resolution of the saved images. The handled formats are "png", "bmp", "tiff"/"tif", "jpeg"/"jpg", and "pdf". The default resolution is 300 (ppi). The resolution does not applies to format pdf. If img.format=NULL (default), the plot is sent to the active device.

Details

To highlight common elements between a list of graphs, the user can focus on nodes (focus = "nodes") or edges (focus = "edges"). As stated in the function list_compar, for a given comparison variable (eg. nd.var="type") if there is multiple nodes/edges with the same value, it is considered to count for as many coincidences as the smaller multiplicity. img.format=NULL (plot to the active device) does not make sense for more than one comparison.

Value

Generates graph decoration images, for pairwise comparisons between two or more decorations, comparing graphs elements (nodes or edges). If img.format=NULL, the plot is sent to the active device and no value is returned. If img.format= "png" or "bmp" or "tiff"/"tif" or "jpeg"/"jpg" or "pdf", the return value is a character vector with the dir/name of every saved image in the indicated format.

See Also

list_compar, plot_dec_grph.

Examples


# Read data
imgs <- read.table(system.file("extdata", "imgs.tsv", package = "iconr"),
                   sep="\t",stringsAsFactors = FALSE)
nodes <- read.table(system.file("extdata", "nodes.tsv", package = "iconr"),
                    sep="\t",stringsAsFactors = FALSE)
edges <- read.table(system.file("extdata", "edges.tsv", package = "iconr"),
                    sep="\t",stringsAsFactors = FALSE)

# Generate list of graphs from the three dataframes
lgrph <- list_dec(imgs, nodes, edges)

# Generate all pairwise comparisons of the graphs with respect to nodes "type"
g.compar <- list_compar(lgrph, nd.var="type")

# Generate the image showing the comparison on common nodes of graphs
# '1' and '4', save it in png format, and return its path.
dataDir <- system.file("extdata", package = "iconr")
outDir <- tempdir()
plot_compar(g.compar, c(1,4), focus = "nodes",
            dir = dataDir,
            dir.out = outDir,
            img.format = "png")

# Generate the image showing the comparison on common edges of all pairwise
# combinations of graphs '1','3', and '4', save them in pdf format, and return
# their path.
# Plot nodes involved in non-common edges in orange and
# nodes involved in common edges and the corresponding labels in brown.
plot_compar(g.compar, c(1, 3, 4), focus = "edges",
            dir = dataDir,
            nd.color = c("orange", "brown"),
            dir.out = outDir,
            img.format = "pdf")

# Save the png image showing the comparison on common nodes of graphs
# '1' and '4'.
# Then read and plot the image.
img.filename <- plot_compar(g.compar, c(1, 4), focus = "nodes",
                            dir = dataDir,
                            dir.out = outDir,
                            img.format = "png")
plot(magick::image_read(img.filename))

# Plot directly on the active device (default) the comparison on common nodes
# of graphs '1' and '4'.
plot_compar(g.compar, c(1, 4), focus = "nodes",
            dir = dataDir)


zoometh/iconr documentation built on Nov. 9, 2023, 10:01 a.m.