Description Usage Arguments Value See Also Examples
Creates a variable with each entry assuming a different colour,
corresponding to levels of a factor. Such a variable is convenient for use with plotting.
The colours chosen are picked by rainbow
, given the number of factor levels.
1 | var.in.colour(myclass, mystart = 0.1, myend = 0.9)
|
myclass |
a factor, or a variable that can be considered as (and transformed into) a factor. Observations that are NA for the input variable are also NA for the resulting colour variable. |
mystart |
the starting value for the colour range from |
myend |
the end value for the colour range from |
A list with the following slots: col_var, containing the variable with the colours, with as many entries as the input variable myclass; list_cols, a vector of colours used, as long as the number of levels/distinct values in myclass; and levels_class, a vector containing the categories of myclass, in the same order as in list_cols.
1 2 3 4 5 6 7 8 | # Create a factor
fcl <- factor(rep(5:3,each=3))
# Now create a vector of colours, one corresponding to each factor level
# as well as objects to be used in a legend
col.cl <- var.in.colour(fcl)
# Make a simple plot displaying the colours and add a legend
plot(as.numeric(as.character(fcl)), col=col.cl[["col_var"]], pch=20, cex=2)
legend("topright", legend=col.cl[["levels_class"]], pch=20, col=col.cl[["list_cols"]] )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.