View source: R/update_diagram.R
update_diagram | R Documentation |
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)
diagram_list |
A required list of data frames returned from the
|
diagram_settings |
An optional list of diagram aesthetic settings. See details for allowable syntax. The following elements are supported and default values are provided:
|
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.
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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.