kwstat / desplot

Plotting experimental designs for field experiments
http://kwstat.github.io/desplot/
Other
22 stars 0 forks source link

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

Open SchmidtPaul opened 1 year ago

SchmidtPaul commented 1 year ago

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 commented 1 year ago

@kwstat Sorry, but any comment on this?