desplot icon indicating copy to clipboard operation
desplot copied to clipboard

Named vector for `col.regions` and `col.text`

Open SchmidtPaul opened this issue 2 years ago • 1 comments

In ggplot() I can use a named vector (where the values are colors and the names are the respective levels) e.g. in scale_color_manual(values = ... ) and it will correctly draw colors per level no matter in which order the levels appear in the data vs. the named vector. If I understand correctly, this does not apply for col.regions = and col.text = in desplot(). Instead, colors must be provided in the same order as the levels in the data.

Am I correct and do you find it worthwhile implementing this suggestion?

Here is an example where I try using a named vector that is sorted in the wrong order and it leads to a mismatch between colors and levels:

require(agridat)
require(desplot)

gen_cols <- c("blue", "gray", "orange")
names(gen_cols) <- rev(levels(yates.oats$gen)) # rev()!

gen_cols
#>    Victory Marvellous GoldenRain 
#>     "blue"     "gray"   "orange"

desplot(
  yates.oats,
  gen ~ col + row,
  col.regions = gen_cols,
  col = nitro,
  text = gen,
  cex = 1,
  aspect = 511 / 176,
  out1 = block
)

Created on 2023-06-13 with reprex v2.0.2

SchmidtPaul avatar Jun 13 '23 10:06 SchmidtPaul

@kwstat Sorry, but any comment on this?

SchmidtPaul avatar Aug 02 '23 07:08 SchmidtPaul