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

adding color and shape options to gl.pcoa.plot #82

Closed
Maschette opened this issue Jul 29, 2019 · 1 comment
Closed

adding color and shape options to gl.pcoa.plot #82

Maschette opened this issue Jul 29, 2019 · 1 comment

Comments

@Maschette
Copy link

Given how frequent modifying color and shapes seems to appear in the dartR google group it is probably worth adding the options to gl.pcoa.plot()

There are three ways to do this with varying levels of flexibility and implementation cost.

  1. add scale_color/shape_manual to the current function, I did this for a previous project and the code is here: https://github.com/Maschette/redartR/blob/master/plot_pcoa.R it adds the options col and shape to the current function so these can be changed. It does also set the default theme to theme_bw because that's what I needed for a publication.

  2. add a new function which returns a ggplot object using ggbuilder which can be edited to modify a range of the ggplot settings. @raymondben had a first pass of this which I forked here: https://github.com/Maschette/redartR

  3. rewrite the function implementing the ggplot2 style guide (https://ggplot2.tidyverse.org/dev/articles/ggplot2-in-packages.html#referring-to-ggplot2-functions) in combination with ggbuilder to give a more flexible function. The advantage of this being people would be able to implement things such as:
    gl.pcoa.plot(glPca, gl)+scale_color_manual(values=...) to change things.

My recommendation for the short term would be implement 1 and explore 2-3.

@raymondben
Copy link

Just a note: you can do option 3 now, because gl.pcoa.plot returns an object of class ggplot:

p <- gl.pcoa.plot(...)
p + theme_bw()

But you can only add new layers, so modifying an existing layer (e.g. to add a shape aesthetic) isn't possible.

Another alternative is to use ggplot_build, which will allow modification of e.g. assigned aesthetics and the underlying data:

p <- gl.pcoa.plot(...)
q <- ggplot_build(p)
## hack q here
plot(ggplot_gtable(q))

But this is probably most suited to relatively advanced users (who will probably be comfortable writing their own plotting function anyway, so might not really be targeting the audience that is asking these questions of the google group. Same probably applies to option (2) above.)

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

3 participants