The function setColors sets the color rules stored in the @meta$colors
slot of a gGraph object. Color rules control how node attribute values
are mapped to colors when plotting.
Arguments
- x
a valid
gGraphobject.- col.rules
a two-column
data.framemapping attribute values to colors.
Value
A gGraph object with the updated color rules.
Details
Color rules must be provided as a two-column data.frame. The first column
must be named after the node attribute and contain its possible values; the
second column must be named "color" and contain valid R color strings.
See also
getColors to retrieve colors or color rules.
Other accessor_methods:
getColors(),
getCoords(),
getCosts(),
getData(),
getEdges(),
getGraph(),
getNodes(),
getNodesAttr(),
setGraph()
Examples
## get current rules
col.rules <- getColors(worldgraph.10k, res.type = "rules")
col.rules
#> habitat color
#> 1 sea blue
#> 2 land green
#> 3 mountain brown
#> 4 landbridge light green
#> 5 oceanic crossing light blue
#> 6 deselected land lightgray
## modify a color
col.rules$color[col.rules$habitat == "sea"] <- "lightblue"
## set back
x <- setColors(worldgraph.10k, col.rules)
getColors(x, res.type = "rules")
#> habitat color
#> 1 sea lightblue
#> 2 land green
#> 3 mountain brown
#> 4 landbridge light green
#> 5 oceanic crossing light blue
#> 6 deselected land lightgray
