set_state_colors() attaches a palette to a network object, so every
figure drawn from it uses the same colours. state_colors(x) <- value is
the replacement form, and state_colors() reads back the colours in use.
One rule holds for colours across the package:
With no colours set, the states are drawn in the Okabe-Ito colours, dealt in the alphabetical order of the states, so a state has the same colour in every figure whatever the order of the network's nodes.
A palette set here replaces those colours for the states it names.
Objects computed from the network carry its colours: groups and their members,
build_clusters(),build_mmm()and the networksbuild_network()andcluster_network()build from them,bootstrap_network(),certainty(),permutation(),bayes_compare(),net_edge_betweenness(),entropy_network(),net_prune(),stability_landscape(),landscape_trend()andlandscape_surface(). A cluster or group that lacks a state keeps the colours of the others.Every figure that colours states follows them:
sequence_plot(),distribution_plot(),plot_state_frequencies(), theplot()methods ofstability_landscape()andlandscape_trend(), andcograph::splot()(through the network'smeta$splotcontract).state_colors =on one of those figures changes that figure only.
Usage
set_state_colors(x, colors)
# Default S3 method
set_state_colors(x, colors)
# S3 method for class 'netobject'
set_state_colors(x, colors)
# S3 method for class 'htna'
set_state_colors(x, colors)
# S3 method for class 'mcml'
set_state_colors(x, colors)
# S3 method for class 'netobject_group'
set_state_colors(x, colors)
state_colors(x) <- valueArguments
- x
A
netobject,netobject_group,mcmlorhtna; any other object raises an error.- colors
The palette: a named character vector of colours, such as
c(plan = "#0072B2", monitor = "#D55E00"). Names are states (for a network built withlabels, the labels it draws), and for anmcmlmay also be cluster names. A name the object does not carry is reported in a message and draws nothing, so one project-wide palette can be attached to every object. States left unnamed are dealt the Okabe-Ito colours the palette does not already use, in the object's state order (recycled when there are more such states than colours). The palette replaces any palette set earlier, andNULLremoves it. An unnamed vector raises an error.- value
The palette, as for
colors, in the replacement formstate_colors(x) <- value.
Value
x with the palette stored on it; the class is unchanged.
state_colors() shows the colours it resolves to. For a netobject or
htna, the palette is also written, in node order, into the
meta$splot producer contract (defaults$node_fill), so
cograph::splot() draws the same colours without being passed any. A
netobject_group stores the palette on the group and on each member
network, so a member drawn on its own carries it too.
See also
state_colors to read the resolved palette back.
Examples
net <- build_network(group_regulation_long, method = "relative",
actor = "Actor", action = "Action", time = "Time")
net <- set_state_colors(net, c(plan = "#0072B2", monitor = "#D55E00"))
state_colors(net)
#> state color source
#> 1 adapt #E69F00 default
#> 2 cohesion #56B4E9 default
#> 3 consensus #009E73 default
#> 4 coregulate #F0E442 default
#> 5 discuss #CC79A7 default
#> 6 emotion #999999 default
#> 7 monitor #D55E00 set
#> 8 plan #0072B2 set
#> 9 synthesis #000000 default