-2

I need to fix the color scaling for a ggplot image I made. This is the image from ggplot...

enter image description here

With the following r code...

  toLonger(dge_cpmlogtwo)  %>% 
  ggplot(aes(x = Expression, color = sample_id)) +
  geom_density() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))

toLonger is an inhouse function. I can't post the data here because its just too large and I don't think it's relevant for the question. Mainly I jsut need to know

Angus Campbell
  • 563
  • 4
  • 19
  • 1
    What exactly do you want to "fix" about this color scaling. Did you question get cut off? It's unclear to me what you are asking. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 27 '21 at 23:17
  • The colors are too similar given the number of variables. They need to be more distinct. I thought that would be visually obvious. For instance can you easily identify the sample name of the outlier? – Angus Campbell Mar 28 '21 at 05:05
  • Its obviously one of the five orangey-red-yellow ones but which one? I want a pallet with distinct colors, I thought that would be obvious just from looking at the post. It doesn't make sense to post a simplified example because this is a highly specific circumstance. – Angus Campbell Mar 28 '21 at 05:07
  • 2
    The human eye can only differentiate between so many colors in a plot like this. The practical limit is 6-8. Maybe only label your outliers (however you are defining that). – MrFlick Mar 28 '21 at 05:07
  • 4
    See here for an in-depth discussion of large categorical color palettes with maximal separation. (TL;DR: it's very hard to do for 25 categories.) https://graphicdesign.stackexchange.com/a/3815 – Jon Spring Mar 28 '21 at 08:58
  • @Jon Spring that's an amazing answer thank you so much for pointing me towards that. – Angus Campbell Mar 28 '21 at 20:39
  • @Jon Spring could you post it as an answer so i can close the question? – Angus Campbell Mar 28 '21 at 20:39
  • @MrFlick "The human eye can only differentiate between so many colors in a plot like this. The practical limit is 6-8. Maybe only label your outliers (however you are defining that)." that's a great suggestion. Thank you. – Angus Campbell Apr 08 '21 at 19:25

1 Answers1

1

It's a surprisingly difficult challenge to identify 25 clearly distinguishable colors. This answer in the graphic design part of stackexchange gives a good overview of some attempts to do so.

A few other places to look:

How to generate a number of most distinctive colors in R?

R color palettes for many data classes

https://stackoverflow.com/a/6076605/6851825

Jon Spring
  • 55,165
  • 4
  • 35
  • 53