plot.sevt {stagedtrees}R Documentation

Plot method for staged event trees

Description

Plot method for staged event tree objects. It allows easy plotting of staged event trees with some options (see Examples).

Usage

## S3 method for class 'sevt'
plot(
  x,
  y = 10,
  limit = y,
  xlim = c(0, 1),
  ylim = c(0, 1),
  main = NULL,
  sub = NULL,
  asp = 1,
  cex_label_nodes = 0,
  cex_label_edges = 1,
  cex_nodes = 2,
  cex_tree_y = 0.9,
  col = NULL,
  col_edges = "black",
  var_names = TRUE,
  ignore = x$name_unobserved,
  pch_nodes = 16,
  lwd_nodes = 1,
  lwd_edges = 1,
  ...
)

make_stages_col(x, col = NULL, ignore = x$name_unobserved, limit = NULL)

Arguments

x

an object of class sevt.

y

alias for limit for compatibility with plot.

limit

maximum number of variables plotted.

xlim

the x limits (x1, x2) of the plot.

ylim

the y limits of the plot.

main

an overall title for the plot.

sub

a sub title for the plot.

asp

the y/x aspect ratio.

cex_label_nodes

the magnification to be used for the node labels. If set to 0 (as default) node labels are not showed.

cex_label_edges

the magnification for the edge labels. If set to 0 edge labels are not displayed.

cex_nodes

the magnification for the nodes of the tree.

cex_tree_y

the magnification for the tree in the vertical direction. Default is 0.9 to leave some space for the variable names.

col

color mapping for stages, one of the following: NULL (color will be assigned based on the current palette); a named (variables) list of named (stages) vectors of colors; the character "stages", in which case the stage names will be used as colors; a function that takes as input a vector of stages and output the corresponding colors. Check the provided examples. The function make_stages_col is used internally and make_stages_col(x, NULL) or make_stages_col(x, "stages") can be used as a starting point for colors tweaking.

col_edges

color for the edges.

var_names

logical, if variable names should be added to the plot, otherwise variable names can be added manually using text.sevt.

ignore

vector of stages which will be ignored and left untouched, by default the name of the unobserved stages stored in x$name_unobserved.

pch_nodes

either an integer specifying a symbol or a single character to be used as the default in plotting nodes shapes see points.

lwd_nodes

the line width for edges, a positive number, defaulting to 1.

lwd_edges

the line width for nodes, a positive number, defaulting to 1.

...

additional graphical parameters to be passed to points, lines, title, text and plot.window.

Examples


data("PhDArticles")
mod <- stages_bj(full(PhDArticles, join_unobserved = TRUE))

### simple plotting
plot(mod)

### labels in nodes
plot(mod, cex_label_nodes = 1, cex_nodes = 0)

### reduce nodes size
plot(mod, cex_nodes = 0.5)

### change line width and nodes style
plot(mod, lwd_edges = 3, pch_nodes = 5)

### changing palette
plot(mod, col = function(s) heat.colors(length(s)))

### or changing global palette
palette(hcl.colors(10, "Harmonic"))
plot(mod)
palette("default") ##

### forcing plotting of unobserved stages
plot(mod, ignore = NULL)

### use function to specify colors
plot(mod, col = function(stages) {
  hcl.colors(n = length(stages))
})

### manually give stages colors
### as an example we will assign colors only to the stages of two variables
### Gender (one stage named "1") and Mentor (six stages)
col <- list(
  Gender = c("1" = "blue"),
  Mentor = c(
    "UNOBSERVED" = "grey",
    "2" = "red",
    "3" = "purple",
    "10" = "pink",
    "18" = "green",
    "22" = "brown"
  )
)
### by setting ignore = NULL we will plot also the UNOBSERVED stage for Mentor
plot(mod, col = col, ignore = NULL)

[Package stagedtrees version 2.3.0 Index]