emmanuelparadis / pegas

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

Current haplotype.r version won't plot other pie colors #55

Closed cajwalsh closed 3 years ago

cajwalsh commented 3 years ago

Hello,

I spent some time yesterday trying to plot a haplotype map with my own custom colour palette for the pie charts. However, in the current version, if the bg argument is specified along with a matrix for pie, the bg palette is made to fill all pie segments in a circle with the same color (the same as col with no pie or bg). Only if the bg argument is not present will the function plot the pie segments different colours, and then of course it is with the default rainbow(). If you specify a new palette with the bg argument in the plot or the pie.colors.function argument in setHaploNetOptions() (either as a character vector of colour names or as a function to return n desired colors similar to rainbow) it appears to be processed correctly (e.g. it shows up as changed in a subsequent getHaploNetOptions()). However, it will not take these changes into account in the plot. The other arguments, as well as colour options in setHaploNetOptions() I tried were changeable in both setHaploNetOptions() command and subsequently plotted accordingly. When I uninstalled 1.0 and reloaded 0.14 several times, proper functionality returned.

Thanks for looking into this and let me know if there is any further way I can help.

emmanuelparadis commented 3 years ago

Hi, Many thanks for reporting this bug. It is fixed. It involved an internal function, so there is no easy way to patch from version 1.0. I've just pushed a fixed version here as pegas 1.0-1. So you can install it from GitHub. Emmanuel

cajwalsh commented 3 years ago

Installed 1.0-1 and works great now. Thanks so much!

NenBarto commented 2 years ago

Hi, I tried using different color functions on version 1.0-1 and still failed. The code below modifies mutations line length, but not colors. Providing a vector of colors doesn't work either.

setHaploNetOptions(pie.colors.function=topo.colors, mutations.sequence.length = 0.1)

Would it be possible to get code of an example that works? Cheers, Nenad

emmanuelparadis commented 2 years ago

Hi, It seems you are right about setHaploNetOptions(pie.colors.function=topo.colors): I'm looking at it.

In the mean time, using a vector of colors works correctly for me. Try this:

example(haploFreq)
f <- function(n) sample(colors(), n)
plot(nt, size = fq, pie = f.loc, bg = f(4))

f(n) gives n random colors, so you could repeat the last line several times.

But:

setHaploNetOptions(pie.colors.function = f)
plot(nt, size = fq, pie = f.loc)

uses rainbow colors, so there's indeed a bug.

emmanuelparadis commented 2 years ago

This is fixed. I've pushed version 1.0-2 here. Thanks for the report.

NenBarto commented 2 years ago

Excellent! Thank you so much for the prompt reply and the bug fix! :)