Winnie09 / Lamian

39 stars 9 forks source link

color palette in plotXDEHm #15

Open resabut opened 1 year ago

resabut commented 1 year ago

Hi, I am trying to plot my XDE results with the plotXDEHm function, but I get this error:
Error: Length of `breaks` should be equal to `colors`.

Debugging brought me to line 142 in plotXDEHm

pt_col_fun = circlize::colorRamp2(seq(1, max(colann$pseudotime)), colorRampPalette(brewer.pal(n = 9, name = "YlGnBu"))(max(colann$pseudotime)))

My max pseudotime value is an integer, say 13.285, so then the breaks and colors arguments have different length.

seq(1, max(colann$pseudotime))
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13
colorRampPalette(brewer.pal(n = 9, name = "YlGnBu"))(max(colann$pseudotime))
 [1] "#FFFFD9" "#F3FAC0" "#E4F4B1" "#CCEBB3" "#A5DCB7" "#7ACBBB" "#54BDC1"
 [8] "#35AAC2" "#1F93C0" "#1F75B3" "#2257A4" "#243D98" "#192B7C" "#081D58"

That is 13 vs 14 elements. I am guessing this is because in the seq function, floats are floored in the from= parameter, whereas they are rounded up in length.out

> seq(1, 2.8)
[1] 1 2
> seq(1, 2, length.out=2.2)
[1] 1.0 1.5 2.0
Winnie09 commented 9 months ago

Thank you @resabut ! I made a note about this and will enhance the plot function in the next version! For now, I guess it will be easier to just modify the function on your end. Please let me know if you need other assistance.