| sn_palette | R Documentation |
Apply a color palette for node and/or edge coloring.
sn_palette(network, palette, target = "nodes", by = NULL)
network |
A cograph_network object, matrix, data.frame, or igraph object. Matrices and other inputs are auto-converted. |
palette |
Palette name or function. |
target |
What to apply the palette to: "nodes", "edges", or "both". |
by |
Variable to map colors to (for nodes: column name or "group"). |
Use list_palettes() to see all available palettes. Common options:
Perceptually uniform, colorblind-friendly.
Optimized for color vision deficiency.
Soft, muted colors.
Saturated, vivid colors.
Shades of gray.
You can also pass a custom palette function that takes n and returns
n colors.
Modified cograph_network object.
cograph for network creation,
sn_theme for visual themes,
sn_nodes for node customization,
list_palettes to see available palettes,
splot and soplot for plotting
adj <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
# Apply palette to nodes
cograph(adj) |> sn_palette("viridis") |> splot()
# Apply to edges
cograph(adj) |> sn_palette("colorblind", target = "edges") |> splot()
# Apply to both
cograph(adj) |> sn_palette("pastel", target = "both") |> splot()
# Custom palette function
my_pal <- function(n) rainbow(n, s = 0.7)
cograph(adj) |> sn_palette(my_pal) |> splot()
# Direct matrix input
adj |> sn_palette("viridis")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.