Git Product home page Git Product logo

Comments (10)

TimTaylor avatar TimTaylor commented on June 24, 2024 1

Vibrant is best for me. Which colour would you use as the default for facets and ungrouped plots?

from incidence2.

thibautjombart avatar thibautjombart commented on June 24, 2024 1

Awesome. Maybe the first of the palette as default color for single plots / no groups? This said, feel free to reorder the colors of the palette if you fancy.

from incidence2.

TimTaylor avatar TimTaylor commented on June 24, 2024

I'm colourblind (red/green) so hopefully help out with the testing of palettes.

With the release of R 4.0 (see https://developer.r-project.org/Blog/public/2019/11/21/a-new-palette-for-r/index.html). Sometimes I find the most colourblind-friendly palettes are not necessarily the nicest looking (this is subjective of course). One additional thing to think about is palette ordering. Sometimes you can get away with a less friendly palette if you are only using a small subset of them.

from incidence2.

thibautjombart avatar thibautjombart commented on June 24, 2024

Not that I'm nessarily advocating for it, but here's one, derived from 'paired' in RColorBrewer, which natively allows up to 12 levels; not color-blind friendly I fear:

## trying colors
### paired tweaked
incidence_pal <- function(n) {
  col <- c("#1F78B4", "#33A02C", "#E31A1C", "#FF7F00", "#6A3D9A", "#B15928", 
           "#A6CEE3", "#B2DF8A", "#FB9A99", "#FDBF6F", "#CAB2D6", "#FFFF99"
           )
  if (n < length(col)) {
    return(col[seq_len(n)])
  }

  colorRampPalette(col)(n)
}


barplot(1:12, col = incidence_pal(12), main = "palette: sorted `paired`")

## 3 colors
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60),
        col = incidence_pal(3), border = "transparent")
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of rows [3]

## 8 colors
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60),
        col = incidence_pal(8), border = "transparent")
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of columns [60]

## 12 colors
barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 12, ncol = 60),
        col = incidence_pal(12), border = "transparent")
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 12, ncol = 60):
#> data length [1000] is not a sub-multiple or multiple of the number of rows [12]

Created on 2020-07-03 by the reprex package (v0.3.0)

from incidence2.

TimTaylor avatar TimTaylor commented on June 24, 2024

From left to right, drop colours 1, 2, 3 and 7 and it works for me

incidence_pal <- function(n) {
  col <- c("#FF7F00", "#6A3D9A", "#B15928", "#B2DF8A", "#FB9A99", "#FDBF6F", "#CAB2D6", "#FFFF99"
  )
  if (n < length(col)) {
    return(col[seq_len(n)])
  }
  
  colorRampPalette(col)(n)
}


barplot(1:8, col = incidence_pal(8), main = "palette: reduced sorted `paired`")

Created on 2020-07-03 by the reprex package (v0.3.0)

from incidence2.

thibautjombart avatar thibautjombart commented on June 24, 2024

This one is derived from the colorbling-friendly categorical variable palettes at: https://personal.sron.nl/~pault/#sec:qualitative
Two versions:

  • vibrant: my favourite, less categories
  • muted: nice too, more categories

I think I also like the colors better, but how does it work for you?

## my preferred, uses https://personal.sron.nl/~pault/#sec:qualitative
col_vibrant <- c(
  "#0077BB",
  "#33BBEE",
  "#009988",
  "#EE7733",
  "#CC3311",
  "#EE3377",
  "#BBBBBB"
  )

col_muted <- c(
  "#332288",
  "#88CCEE",
  "#44AA99",
  "#117733",
  "#999933",
  "#DDCC77",
  "#CC6677",
  "#882255",
  "#AA4499",
  "#BBBBBB"
  )


make_palette <- function(x) {
  function(n) {
    if (length(x) > n) {
      x[seq_len(n)]
    } else {
      colorRampPalette(x)(n)
    }
  }
}


#### vibrant palette
pal_vibrant <- make_palette(col_vibrant)
barplot(1:7, col = pal_vibrant(7), main = "palette: vibrant")

barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60),
        col = pal_vibrant(3))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of rows [3]

barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60),
        col = pal_vibrant(8))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 8, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of columns [60]

#### muted palette
pal_muted <- make_palette(col_muted)
barplot(1:7, col = pal_muted(7), main = "palette: muted")

barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60),
        col = pal_muted(3))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 3, ncol = 60): data
#> length [1000] is not a sub-multiple or multiple of the number of rows [3]

barplot(matrix(sample(1:10, 1000, replace = TRUE), nrow = 10, ncol = 60),
        col = pal_muted(10))
#> Warning in matrix(sample(1:10, 1000, replace = TRUE), nrow = 10, ncol = 60):
#> data length [1000] is not a sub-multiple or multiple of the number of columns
#> [60]

Created on 2020-07-03 by the reprex package (v0.3.0)

from incidence2.

TimTaylor avatar TimTaylor commented on June 24, 2024

Now implemented. What do you think about the default for the column borders (white or NA)

from incidence2.

thibautjombart avatar thibautjombart commented on June 24, 2024

Morning! I was trying to test both to compare and found this issue. I think it may come from the borders (bars are so thin we see only the border)? If that is the case, that could be an element to consider in the default. My thinking would be:

  • transparent border: safer for thin bars (if that's the issue)
  • grey / black border: may be better contrast between colors (not even sure if that's true)

from incidence2.

thibautjombart avatar thibautjombart commented on June 24, 2024

On an unerlated point: maybe it would make sense to plot the missing (NA) group as grey?

from incidence2.

TimTaylor avatar TimTaylor commented on June 24, 2024

Are we happy to close this now?

from incidence2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.