vtree icon indicating copy to clipboard operation
vtree copied to clipboard

specfill argument does not allow for more than 9 colors

Open mac471 opened this issue 7 months ago • 0 comments

I am trying to create a tree that involves a categorical variable that has more than 9 values. I am using the specfill argument to specify each value=hex color pair. This works great if the number of different values is 9 or less. When 10 or more, specfill is ignored and vtree defaults to using a color gradient.

Here is a simple reprex that works:

dataDf <- data.frame(Level1 = c("One","Two","Three","Four","Five","Six","Seven","Eight","Nine"))

vtree(dataDf,"Level1", specfill = list(Level1 = c("One"="green","Two"="orange","Three"="purple","Four"="pink","Five"="white","Six"="black","Seven"="brown","Eight"="gray","Nine"="yellow")))

If you increase the number of values that "Level1" can take from 9 to 10, the specfill colors are ignored:

dataDf <- data.frame(Level1 = c("One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"))

vtree(dataDf,"Level1", specfill = list(Level1 = c("One"="green","Two"="orange","Three"="purple","Four"="pink","Five"="white","Six"="black","Seven"="brown","Eight"="gray","Nine"="yellow","Ten"="tan")))

Line 2196 in vtree.R has this comment: # Too many values to permit distinct colors

Line 2195 in vtree.R: (Nnonmissing>length(col) is TRUE when the number of nodes is 10 or more (col is a hardcoded list with 9 entries):

if (is.null(fillcolor) & (Nnonmissing>length(col) || (seq & (vars[i]=="sequence")) || (pattern & (vars[i]=="pattern")) || (row==0))) {

I can see that this function has a ton of arguments and I haven't read through the entire function but it seems like the test should include is.null(specfill) e.g.,:

if (is.null(fillcolor) && is.null(specfill) && (Nnonmissing>length(col) ||...

When I make this change, specfill is observed and my categorical variables can have more than 9 different colors that I control via specfill.

I really enjoy using this package. Keep up the good work!

mac471 avatar Jul 09 '24 01:07 mac471