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

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

Open
SchmidtPaul opened this issue Jun 13, 2023 · 1 comment
Open

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

SchmidtPaul opened this issue Jun 13, 2023 · 1 comment

Comments

@SchmidtPaul
Copy link

SchmidtPaul commented Jun 13, 2023

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
Copy link
Author

@kwstat Sorry, but any comment on this?

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

1 participant