plot_dec_grph: Plot a Graph on a Decoration

View source: R/plot_dec_grph.R

plot_dec_grphR Documentation

Plot a Graph on a Decoration

Description

Plot with nodes only, edges only, or both (geometric graph) over a decoration image.

Usage

plot_dec_grph(
  nodes = NULL,
  edges = NULL,
  imgs,
  site,
  decor,
  dir = getwd(),
  nd.var = "id",
  nd.color = "orange",
  nd.size = 0.5,
  lbl.color = "black",
  lbl.size = 0.5,
  ed.color = c("orange", "blue"),
  ed.lwd = 1,
  dir.out = dir,
  out.file.name = NULL,
  img.format = NULL,
  res = 300
)

Arguments

nodes

dataframe of nodes.

edges

dataframe of edges.

imgs

dataframe of decorations.

site

name of the site.

decor

name of the decoration.

dir

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

nd.var

field name in the nodes data frame to be displayed as node labels. By default the identifier nodes$id.

nd.color, nd.size, lbl.color, lbl.size, ed.color, ed.lwd

graphical parameters for color and size/widths of nodes, edges, and labels. ed.color is a vector with two values (the second value is used for diachronic edges).

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

plot nodes only (if edges = NULL), edges only (if nodes = NULL), or both (graph) over a decoration image.

Value

Generates graph decoration images with nodes, edges, or both, overlapping the decoration image. 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 the saved image in the indicated format.

Examples


## Set data folder
dataDir <- system.file("extdata", package = "iconr")
## Decoration to be plotted
site <- "Brozas"
decor <- "Brozas"
## Read nodes, edges, and decorations
nds.df <- read_nds(site, decor, dataDir)
eds.df <- read_eds(site, decor, dataDir)
imgs <- read.table(paste0(dataDir, "/imgs.tsv"),
                   sep="\t", stringsAsFactors = FALSE)

## Plot 'Brozas' nodes and edges on the active device
## with node variable "type" as labels
plot_dec_grph(nds.df, eds.df, imgs,
              site, decor,
              dir = dataDir,
              lbl.size = 0.4,
              nd.var = "type")

## Save only edges of 'Brozas' with bigger widths and in image format jpg.
outDir <- tempdir()
img.filename <- plot_dec_grph(nodes = NULL, eds.df, imgs,
                              site, decor,
                              dir = dataDir,
                              ed.lwd = 2,
                              dir.out = outDir,
                              img.format = "jpg")
## Then read and plot the image.
a.dec <- magick::image_read(img.filename)

## Inspect the output image
magick::image_info(a.dec)

## Plot the output image
plot(a.dec)


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