Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate unique colors for categorical color argument to plotSPC #9

Closed
dylanbeaudette opened this issue Jun 23, 2016 · 4 comments
Closed

Comments

@dylanbeaudette
Copy link
Member

plotSPC does not generate enough colors in the legend (?) when coloring horizons with categorical data containing more than 8 unique values.

@pierreroudier
Copy link
Collaborator

This is a limitation of RColorBrewer isn't it?

A more flexible method could be to distribute the N colours evenly on a HSV circle. I think this is what ggplot2 is doing by default. This may be facilitated by the colorspace package by the looks of things.

@pierreroudier
Copy link
Collaborator

Another solution would be random colours. Some good pointers:

https://stackoverflow.com/questions/15282580/how-to-generate-a-number-of-most-distinctive-colors-in-r
http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/

@dylanbeaudette
Copy link
Member Author

Good idea. I suppose than more than 8-10 classes is not our responsibility as the legend becomes impossible to use. Random colors would be nice so as not to convey some kind of ordering when there is none.

Several possible paths:

  1. character class, use random colors
  2. factor class, use default ordered colors after expanding with colorRampPalette
  3. in the case of >8-10 classes, issue a warning

There is still a problem with the legend: the current implementation doesn't scale well to > 8 classes.

dylanbeaudette added a commit that referenced this issue Feb 7, 2019
@dylanbeaudette
Copy link
Member Author

I think that this issue is now 90% solved:

  • colors are mapped to categorical data, even when n > length(col.palette)
  • the legend is split into 2 rows when n > n.legend

image

image

Try it out.

library(aqp)

data(sp3)
depths(sp3) <- id ~ top + bottom

# make some fake categorical data
horizons(sp3)$fake.data <- sample(letters[1:15], size = nrow(sp3), replace=TRUE)

# better margins
par(mar=c(0,0,3,1))

# note that there are enough colors for 15 classes (vs. previous limit of 10)
# note that the legend is split into 2 rows when length(classes) > n.legend argument
plot(sp3, color='fake.data', name='fake.data', cex.names=0.8)

# make enough room in a single legend row
plot(sp3, color='fake.data', name='fake.data', cex.names=0.8, n.legend=15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants