plot_dec_grph: Plot a Graph on a Decoration

Description Usage Arguments Details Value Examples

View source: R/plot_dec_grph.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## 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)

iconr documentation built on Feb. 16, 2021, 5:06 p.m.