emmanuelparadis / pegas

Population and Evolutionary Genetics Analysis System
GNU General Public License v2.0
27 stars 10 forks source link

Problem with the display of pie chart's colors with haplotype network median joining #68

Closed ColineRoyaux closed 2 years ago

ColineRoyaux commented 2 years ago

Hey !

I just discovered this awesome package to make haplotype networks and very happy about it ! Just I had a small problem with the display of the median joining method. Indeed, if I want to show pie charts on each of my haplotypes, the pieces are right but it's all in the same color ... I found it's probably because of the default parameters of plot.mjn() in parameter bg that are c("green", "slategrey").

So, I tried to put back the rainbow() function in bg but it won't work as in the plot.mjn() function, there is a subset of bg made to use a different color for the median vectors and functions can't be subsetted ... I tried many things such as creating a new palette with enough colors for haplotypes and median vectors, or making a matrice of colors but still it won't work I only have the first color of the palette displaying on every pie chart. Do you know anything I can do to make it work ?

Thank you so much !

ColineRoyaux commented 2 years ago

Forgot to mention that the only way I found to display different colors in pieces of pie charts is to put bg = NULL but it makes it impossible to change colors in the pie charts (even when I change the pie.colors.function parameter with setHaploNetOptions) and the legend displays without the colors so impossible to know which color represents what.

cajwalsh commented 2 years ago

Hi Coline!

Check out Emmanuel's responses to this thread (https://github.com/emmanuelparadis/pegas/issues/55). There have been a few different fixes made so maybe something in here will help. You may want to try updating your package through the CRAN or installing the development/github version. Hope this helps!

ColineRoyaux commented 2 years ago

Hi Cameron !

Thank you I haven't seen this Issue before ! Unfortunately it is still not working on my side and I have the last version of pegas... In the issue #55, the bug could be fixed by not providing a value to the bg parameter. Here, as I use a median joining network, the bg parameter has a default value in plot.mjn() so it cannot be ignored or I don't know how to reset this default value.

ColineRoyaux commented 2 years ago

I just found a quick fix on this matter. It's a bit dirty but if you change the class of the mjn R object with attr(mj_net, "class") <- "haploNet" it's all fixed ! Only problem : median vectors and haplotypes are displayed with the same symbol and colors but if you put a list of the shapes you want for each in shapes = you should be okay !

emmanuelparadis commented 2 years ago

Hi Coline and Cameron,

Great to see that you found your way with pegas! Yes, the plot method for "mjn" objects is not flexible, so your solution is certainly the best one (you could do simply: class(mj_net) <- "haploNet"). I'll add a note in the help page on this point.

While looking at this issue, I found a bug in plot.haploNet: if bg is a vector of colours, this is not handle correctly when drawing the haplotype symbols. This also affects plot.mjn. I have fixed it and pushed here (you need to reinstall the package because the bug was in an internal function). Coline: this bug should not affect your current analyses.

Best, Emmanuel

ColineRoyaux commented 2 years ago

Thank you so much Emmanuel ! I'm closing this issue then :)