R/update_diagram.R
update_diagram.Rd
This function takes a list as created by prepare_diagram
and allows the user to update the styling of the boxes and arrows by setting
the different arguments in the input list of this function.
update_diagram(diagram_list, diagram_settings = NULL)
A required list of data frames returned from the
prepare_diagram
function. See that function for details
about this object.
An optional list of diagram aesthetic settings. See details for allowable syntax. The following elements are supported and default values are provided:
var_xmin
: A named numeric vector of offsets to mininum x locations.
var_xmax
: A named numeric vector of offsets to maximum x locations.
var_ymin
: A named numeric vector of offsets to minimum y locations.
var_ymax
: A named numeric vector of offsets to maximum y locations.
var_xlabel
: A named numeric vector of offsets to variable label x locations.
var_ylabel
: A named numeric vector of offsets to variable label x locations.
var_outline_color
: A named character vector of box outline colors.
Default is "black".
var_fill_color
: A named character vector of box fill colors. Can be
a named color or HEX code. Default is "#6aa4c8".
var_label_text
: A named character vector of label text for each flow.
var_label_color
: A named character vector of variable label colors.
Can be a named color or HEX code. Default is "white".
var_label_size
: A named character vector of text sized for variable
labels. Default is 10.
flow_xstart
: A named numeric vector of offsets to the minimum x
locations (flow starting points).
flow_xend
: A named numeric vector of offsets to the maximum x
locations (flow ending points).
flow_ystart
: A named numeric vector of offsets to the minimum y
locations (flow starting points).
flow_yend
: A named numeric vector of offsets to the maximum y
locations (flow ending points).
flow_xlabel
: A named numeric vector of offsets to the flow label x locations.
flow_ylabel
: A named numeric vector of offsets to the flow label y locations.
flow_curvature
: A named numeric vector numeric curvature values.
flow_line_color
: A named character vector specifying the color of
of flow lines. Default is "black".
flow_line_size
: A named numeric vector of line sizes. Default
value is 1.
flow_line_type
: A named character vector of linetypes. This
argument is passed to the linetype
argument in ggplot2. From
the ggplot2 documentation: "The linetype aesthetic can be specified
with either an integer (0-6), a name (0 = blank, 1 = solid, 2 = dashed,
3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash), a mapping to a
discrete variable, or a string of an even number (up to eight) of
hexadecimal digits which give the lengths in consecutive positions in
the string." flowdiagramr uses the character name. Default is "solid".
flow_label_text
: A named character vector of label text for each flow.
flow_label_color
: A named character vector of label colors. Default
is "black".
flow_label_size
: A named numeric vector of label text sizes. Default
value is 5.
flow_show_label
: A named logical vector of whether to display flow
labels (TRUE) or not (FALSE). Default value is TRUE.
flow_arrow_size
: A named numeric vector of arrow head sizes. Default
value is 0.25.
flow_show_arrow
: A named logical vector of whether to display flows
(TRUE) or not (FALSE). Default value is TRUE.
The same list of data frames that was sent into the function with updated style settings (different values in the updated columns/variables) of the data frames.
The user can provide any number of updates in the
diagram_settings
list. Only those provided are updated. If the
function is called with no updates, the names of all elements in
the variables
and flows
data frames are returned.
For location settings (e.g., xmin)
and curvature settings (just for flows), the user must provide a named
vector for the setting argument, where the name matches one or more of
variables$name
(for var_* settings) or flows$name
(for flow_*
settings). For visual aesthetics for variables (e.g., fill_color), the
user must specify a named vector where the name is either "all"
(aesthetic value for all variables) or the name matches one one or more
of the variables$name
. For visual aesthetics for flows (e.g.,
line_color), the user must specify a named vector, where allowable
names are: "all" (color for all lines, regardless of type or name),
"main" (color for main flows), "interaction" (color for interaction
flows), "external" (color for external flows), "generator" (color for
all generator flows), or the name of one of the
character values in flows$name
. If a mix of type and name are supplied,
the type is applied first and name-specific values are applied second.
See examples.
# basic model specification
variables <- c("S","I","R")
flows <- list(S_flows = c("-b*S*I"),
I_flows = c("b*S*I","-g*I"),
R_flows = c("g*I"))
mymodel <- list(variables = variables, flows = flows)
diag_list <- prepare_diagram(model_list = mymodel)
# make all variable boxes green
new_setts <- list(var_fill_color = c(all = "green"))
new_list <- update_diagram(diag_list, new_setts)
# make just the S box green
new_setts <- list(var_fill_color = c(S = "green"))
new_list <- update_diagram(diag_list, new_setts)
# make all flow lines red
new_setts <- list(flow_line_color = c(all = "red"))
new_list <- update_diagram(diag_list, new_setts)
# make main flow lines red
new_setts <- list(flow_line_color = c(main = "red"))
new_list <- update_diagram(diag_list, new_setts)
# make the b*S*I interaction flow line red
new_setts <- list(flow_line_color = c(i_bSI = "red"))
new_list <- update_diagram(diag_list, new_setts)
# make all flow lines green except for b*S*I interaction flow, which is blue
new_setts <- list(flow_line_color = c(all = "green", i_bSI = "blue"))
new_list <- update_diagram(diag_list, new_setts)
# combine variable and flow settings
new_setts <- list(flow_line_color = c(all = "green", i_bSI = "blue"),
var_fill_color = c(all = "red", S = "cyan"))
new_list <- update_diagram(diag_list, new_setts)
# more extensive updates
newsettings <- list(var_label_color = c(S = "green", I = "blue", R = "red"),
flow_line_size = c(interaction = 1.5),
flow_line_color = c(all = "grey25",
interaction = "orange",
m_bSI = "red"))
diag_list3 <- update_diagram(diag_list, diagram_settings = newsettings)