statnet / statnetWeb

A graphical user interface for network modeling with the 'statnet' software
GNU General Public License v3.0
29 stars 17 forks source link

Plotting legend #2

Closed martinamorris closed 10 years ago

martinamorris commented 10 years ago

fix colors

ebey commented 10 years ago

currently the colors in the legend only match the corresponding nodes for numeric attributes.

how does plot.network translate a non-numeric attribute into a color?

skyebend commented 10 years ago

it uses network's (undocumented) as.color() function: as.color function (x) { if (is.numeric(x)) { if (any(x != round(x), na.rm = TRUE)) { return(gray((x - min(x))/(max(x) - min(x)))) } else return(x) } if (is.factor(x)) { return(match(levels(x)[x], levels(x))) } if (is.character(x)) { if (all(is.color(x))) return(x) else { return(match(x, sort(unique(x)))) } } }

which seems to be basically mapping each element (or factor level) to an integer value and then using the default palette

ebey commented 10 years ago

Thanks Skye!

The fill colors are fixed in commit cc4e503