Remove default colorscale legend when using a custom colorscale using two symbols

Hi,

I am trying to build an interactive plot that has “paired points”. Each point in a pair has a different shape/symbol. However, all points share the same (custom) color scale.

I have a functional plot. However, for some reason I don’t know, there is always a default viridis colorscale that I cannot get rid of:

And, after highlighting a point, my custom colorbar shows through:

This is the code I’m using to generate the figure:

tmp <-   highlight_key(tmp_hsp_both, ~name_long)

plot_ly(tmp,
            x=~log2FoldChange_D1, y=~log2FoldChange_D3, 

            symbol = ~group,
            symbols=c("HSP90i"="circle", "Combination"="triangle-up"),
            
            size=~sig_time,
            
            color=~log2FoldChange_time2,
            
            # colorscale = list(
            #       scales::rescale( c(
            #           min(tmp_hsp_both$log2FoldChange_time, na.rm = T),
            #           0,
            #           max(tmp_hsp_both$log2FoldChange_time, na.rm = T)
            #       ) ),
            #       c("#1E90FF","#ffffff","#ff0000")
            #   ),
            
            showscale = FALSE,
            
            text = ~name_long,
            hoverinfo = 'text',
            hovertext = ~paste(name_long),

            type="scatter", mode="markers", showlegend = F,

            marker=list(
              line = list(color="#000000", width = 2),
              colorscale = list(
                  scales::rescale( c(
                      min(tmp_hsp_both$log2FoldChange_time, na.rm = T),
                      0,
                      max(tmp_hsp_both$log2FoldChange_time, na.rm = T)
                  ) ),
                  c("#1E90FF","#ffffff","#ff0000")   ),
              colorbar=list(
                  title='log2FC time',
                  len = 0.5 ),
              showscale = TRUE
            )
  )  %>%
  layout(
    shapes = list(
        list(
          type = "line", 
          x0 = -100, y0 = -100,       
          x1 = 100, y1 = 100, 
          line = list(color = "#505050", dash ="dash")
        ),
        list(
          type = "line", 
          x0 = -100, y0 = 100,
          x1 = 100, y1 = -100,
          line = list(color = "#505050", dash ="dash")
        )
      ),

    xaxis = list(range = range(tmp_hsp_both$log2FoldChange_D1)+c(-0.1, 0.1),
                 fixedrange = TRUE),
    yaxis = list(range = range(tmp_hsp_both$log2FoldChange_D3)+c(-0.1, 0.1),
                 fixedrange = TRUE)
    ) %>%
  highlight(on = "plotly_hover", off = "plotly_doubleclick")


I’ve tried several variations of showscale = FALSE, hide_colorbar(), moving the color=~... or colorscale = ... in or out of marker … but nothing worked.

Do you have any suggestion of how can I get rid of the default legend?

Thanks


This is the data I used:

> dput(tmp_hsp_both)
structure(list(name_long = structure(c(1L, 2L, 40L, 30L, 14L, 
21L, 34L, 3L, 4L, 28L, 37L, 17L, 22L, 27L, 25L, 5L, 18L, 19L, 
24L, 13L, 26L, 23L, 20L, 6L, 38L, 15L, 8L, 35L, 12L, 11L, 7L, 
10L, 39L, 32L, 36L, 29L, 16L, 33L, 31L, 9L, 1L, 2L, 21L, 4L, 
40L, 3L, 34L, 22L, 14L, 30L, 5L, 25L, 18L, 28L, 37L, 17L, 27L, 
23L, 26L, 24L, 35L, 13L, 19L, 38L, 11L, 20L, 10L, 33L, 15L, 9L, 
8L, 32L, 29L, 31L, 36L, 7L, 39L, 6L, 16L, 12L), levels = c("HSP90AA1", 
"HSP90AA2P", "HSP90AA3P", "HSP90AB1", "HSP90AB3P", "HSP90B1", 
"HSP90B2P", "HSPA12A", "HSPA12A-AS1", "HSPA12B", "HSPA13", "HSPA14", 
"HSPA1A", "HSPA1B", "HSPA1L", "HSPA2", "HSPA4", "HSPA4L", "HSPA5", 
"HSPA6", "HSPA8", "HSPA8P1", "HSPA8P5", "HSPA8P7", "HSPA8P8", 
"HSPA8P9", "HSPA9", "HSPB1", "HSPB11", "HSPB8", "HSPB9", "HSPBAP1", 
"HSPBP1", "HSPD1", "HSPD1P1", "HSPD1P11", "HSPD1P4", "HSPE1", 
"HSPG2", "HSPH1"), class = "factor"), padj_D1 = c(1.56195991220308e-86, 
5.81735442583228e-44, 4.34730762657343e-38, 1.28886800842124e-31, 
6.26347958011826e-26, 1.01378753339486e-23, 7.86473783694471e-23, 
1.40341428639765e-21, 1.60236023870612e-21, 8.72994697370012e-17, 
1.36323212426438e-13, 1.25660875553279e-12, 1.26800879525755e-09, 
3.71448446451216e-09, 1.79850018986659e-07, 1.78499593454276e-06, 
2.41720764481194e-06, 8.48302512082772e-05, 0.00678713197170793, 
0.0102491071261514, 0.0200390756019445, 0.0208727299744021, 0.089883055774021, 
0.113665704535474, 0.148329390123437, 0.427574918210521, 0.678379498641083, 
0.700821287120752, 0.734530429866413, 0.829802667178188, 0.858121084325597, 
0.858749038757322, 0.925221607469276, 0.985396695376303, 0.994516329279154, 
0.997576700369978, 0.997576700369978, 0.997576700369978, 0.997576700369978, 
0.999806792058613, 7.90738134926293e-121, 6.81217381738295e-66, 
7.60099924289927e-47, 8.15993750545015e-43, 8.16303346946137e-36, 
1.98141532700828e-34, 2.38162387691446e-27, 1.74423311329566e-21, 
2.50495619190235e-21, 6.17898132968734e-19, 4.90033374237764e-18, 
6.08365690581437e-18, 8.54267951250474e-15, 1.23207052065827e-14, 
3.5347564024618e-13, 8.4577727195756e-13, 2.70827043170927e-10, 
8.24637937676715e-10, 2.29497824012266e-06, 0.000244155292712348, 
0.000948681456929262, 0.00304964280262962, 0.0138674217743644, 
0.0322159821614746, 0.145177294095521, 0.161217898717558, 0.182760691573196, 
0.191386774107936, 0.25287589852108, 0.517704802127332, 0.625145343622218, 
0.803568603911314, 0.815319229614064, 0.850911139708018, 0.870435118454082, 
0.902854259423059, 0.904734342827845, 0.944545517290031, 0.945034067202838, 
0.965953975530374), log2FoldChange_D1 = c(1.33038977650303, 1.3444758583569, 
0.786030673385936, 0.757018622063837, 1.23661117158291, 0.611191848523554, 
0.52493632628873, 1.19637627902831, 0.523306017522778, 0.76874864122013, 
0.733882648576387, 0.483891998577036, 0.5857126761991, 0.295943090630018, 
0.575213653735914, 0.513343385990329, 0.477961067611478, -0.2177720441793, 
0.762464448328788, 1.13451395879071, 0.553828192552907, 0.523531098996872, 
0.412050809320605, -0.133195390330762, 0.543183338062755, 0.0201724453419408, 
0.0572946806826973, 0.0130232573226265, 0.0493048513356615, -0.0499152585495652, 
-0.018003753347179, -0.0199005706207784, -0.0146321808866447, 
-0.0117614282669834, -0.00278883647506179, 0.00907425637658555, 
0.00778781461866647, -0.00739603714498643, 0.00388060677778794, 
0.00182886713639444, 1.56893387494028, 1.62826166618505, 0.837898621129523, 
0.739449611477915, 0.77014290554252, 1.51505117153228, 0.576020062520646, 
0.880156155593451, 1.12280103033953, 0.607846323733077, 0.86649628950772, 
0.900673985120867, 0.742740072766588, 0.716760125833356, 0.726536273886679, 
0.483433897277366, 0.316439971024379, 1.1491199924552, 0.942716901199274, 
0.899249832595276, 1.61563457909588, 1.15071326455505, -0.144044901041817, 
0.631970017828793, -0.141790583661059, 0.214317131256718, -0.164251185545347, 
-0.146588975453281, 0.0702498754876476, 0.0420328427337066, 0.0783654586702135, 
0.0339778083263673, -0.0355108200008695, 0.0144140933126569, 
-0.00890550696582149, -0.0144024188643716, -0.0150571389859887, 
0.0112680002180472, -0.0139404756883351, -0.00862228329056192
), padj_D3 = c(3.08993028118079e-10, 3.5120264147189e-06, 0.000985965275009306, 
6.51756434763505e-06, 0.0169109908320694, 0.924874847529133, 
0.000121270983667365, 0.0266778562826831, 0.0598859547445212, 
2.1497028311887e-16, 0.178358595585615, 0.0356759800680177, 0.634510556393593, 
0.850058373322672, 0.999310227974134, 0.0634814460362411, 6.1013757387798e-05, 
0.0112320214073284, 0.801955367540365, 0.886151124841837, 0.957725703927902, 
0.792595189646555, 1.58103266581647e-06, 0.000209888638371789, 
0.966391385700933, 0.884923268784307, 0.74454355479041, 0.565179956152341, 
0.794868929749536, 0.530199877803467, 0.340128528517155, 0.712903886311628, 
0.899028193806845, 0.859939066266983, 0.884303007951212, 0.788539356870914, 
0.00945745967029274, 0.950259772536847, 0.921197673286913, 0.974313433624376, 
0.00879558404805983, 0.0949656568496729, 0.0224919422503821, 
1.02110040041418e-07, 0.153765728304791, 0.748404217565674, 0.00114285402020097, 
0.728324654480497, 0.708963965699747, 8.92912416934054e-26, 7.48520150831519e-06, 
0.903356452293227, 3.78825227062968e-16, 2.99482403382703e-23, 
0.146364670256293, 0.0083666821636425, 0.392433630642975, 0.0399651705434007, 
0.0488878816214472, 0.766334020760189, 0.68304291524307, 0.820300829759562, 
0.35524774270438, 0.679805543543565, 0.00647376430008086, 0.0132180357691241, 
0.724903147921649, 0.833548022942854, 0.798797424642611, 0.952696127279948, 
0.955588995644423, 0.738565635475016, 0.227831030835771, 0.930584760576338, 
0.930282878976924, 0.339841869113243, 0.956718683681148, 1.49918526437746e-12, 
5.76089693621535e-05, 0.681532677602824), log2FoldChange_D3 = c(0.45069801795096, 
0.476901307284202, 0.227734028931592, 0.324806194720054, 0.303863367609356, 
-0.00912574493601964, 0.22536357741877, 0.298278888905265, 0.127163240860214, 
-0.767669233678141, 0.153083668299239, 0.169035967930203, -0.0660322334571526, 
0.0248069510397312, -0.00298665496479577, 0.206326354228816, 
0.401893937257676, -0.146208098218933, -0.0333023912203949, 0.0146899762685001, 
-0.00879757867283257, 0.0384325490999213, -0.999960759491783, 
-0.23674029856452, 0.00652069202431298, -0.0133213980820769, 
-0.0513065957753437, 0.0330069087385707, 0.0389174603216281, 
-0.0752386101102122, -0.0894456221944168, -0.0430276144415445, 
-0.0170106687985186, -0.0282321337103443, 0.00937939410934019, 
0.0440055630431529, 0.313685963040908, -0.0130705050731169, 0.00962553075717169, 
0.00442125003982844, 0.198775118475605, 0.1838747308313, 0.162270768194218, 
0.298122623237353, 0.111487381709375, -0.0533431019662694, 0.189761688131109, 
0.0507904657310256, 0.0626085457154485, 0.691298521872501, 0.451986474210393, 
0.02068152299502, 0.755899165515545, -0.912740768892206, 0.163525228746207, 
0.191987663207264, 0.0605919943527952, 0.355601654963072, 0.348427815678497, 
0.06284199275454, 0.0495593196760805, 0.0367202190818042, -0.0653662390873273, 
0.0670996222930913, -0.230170975565606, -0.465727840110533, -0.064207235844052, 
0.0351334210054378, 0.0389668668949419, 0.0109177080535643, -0.00959757074013955, 
0.0632996654198241, -0.173390604861751, -0.0132394359248744, 
0.0104336637616636, -0.157694492104745, -0.011984695097748, -0.432380538915443, 
-0.480135118296817, -0.0673118082292244), padj_time = c(5.9318583175155e-46, 
3.95192676672487e-22, 4.96760357355941e-24, 3.19022319007022e-14, 
3.85235854056055e-17, 1.01483184603741e-32, 3.05428785450363e-09, 
2.72846601658741e-14, 9.59766517612352e-15, 8.01766859252881e-87, 
4.56632949012508e-10, 8.17356702972729e-07, 4.42384523641894e-18, 
1.35755077574029e-10, 1.37591436250713e-10, 0.00598606236906608, 
0.599892103497394, 0.222992308052232, 2.15363439838156e-06, 0.000736691105073876, 
0.000188096105787846, 0.0086130136602521, 2.43225343008012e-20, 
0.271433560366198, 0.0145536255451846, 0.0109947831196411, 0.011157878287438, 
0.78431259810421, 0.528474669831846, 0.962957293867826, 0.833334936773231, 
0.816963875108606, 0.650924081046603, 0.952618936783447, 0.442544749816588, 
0.87077944448952, 0.00331988996435383, 0.965838283750166, 0.943735411829604, 
0.970473767502931, 6.08212838890367e-113, 9.1953265587606e-64, 
9.66062567585599e-39, 7.50559155048252e-19, 1.81116141938256e-33, 
8.31228437506928e-50, 1.26733890766021e-15, 1.58715393954805e-24, 
5.09792703040034e-24, 0.318643539095959, 2.21091959135598e-05, 
3.34446040981066e-22, 0.948540396197368, 9.52198734651122e-95, 
4.8983465189689e-10, 3.2307936469184e-06, 4.77827419464722e-09, 
1.83995018124067e-05, 0.00632799379863655, 0.00014210554871164, 
0.0004474528919913, 0.00085117160047564, 0.113054313550302, 0.0483277852880166, 
0.503158661317834, 6.54382514561991e-08, 0.245112497715199, 0.0183815340253941, 
0.252765796372712, 0.373020110217681, 0.352747397562547, 0.999256705860019, 
0.416732652900733, 0.623161487849216, 0.65754472300286, 0.431235308208901, 
0.899581048582446, 1.18141540489915e-16, 2.28215941134478e-05, 
0.69467674221319), log2FoldChange_time = c(-0.862944930337323, 
-0.821495040691004, -0.53529566888596, -0.413727295318221, -0.861649012400456, 
-0.625378856491763, -0.284667087341167, -0.821156979407452, -0.378241572744422, 
-1.57115848331996, -0.522190510192359, -0.293980540488672, -0.700568528879427, 
-0.27374798241163, -0.586785638491822, -0.252186832534191, -0.057579825419937, 
0.0725961311645395, -0.98050780193218, -0.994699036429169, -0.624973363057576, 
-0.407625568750749, -1.59583773659725, -0.0745222937447902, -0.592479302422313, 
-0.796093452265886, -0.273890211216892, -0.0281250736282331, 
-0.0775395740713297, 0.00554454392175638, -0.0270971118847851, 
0.0336715127832262, 0.057755649045473, 0.0118659258759281, 0.0493746528032823, 
0.0244113938309907, 0.300961097113397, 0.00794397851696068, -0.00827234042544274, 
-0.0043134543256195, -1.35076109716791, -1.41760508565058, -0.678320601935102, 
-0.428124639436631, -0.646468799070835, -1.60305469405614, -0.375163597100949, 
-0.829530226497803, -1.04428908102314, 0.0723330151558734, -0.37771600704102, 
-0.876340169852013, 0.00960083839943577, -1.66098626656211, -0.531809442138136, 
-0.284766529463218, -0.256262579295557, -0.668206465620295, -0.445595052163749, 
-0.773664481955359, -1.28307559589586, -1.00636175872241, 0.0851117870474247, 
-0.412339465538486, -0.0649237856362428, -0.936404181263657, 
0.174994120440852, 0.215874806209058, -0.142288403633763, -0.105269832498051, 
-0.11288413569138, 0.000119215953516355, -0.105526763359125, 
-0.0543304993912026, 0.0366305989077294, -0.108420413620987, 
0.0211120357859741, -0.449437636815058, -0.456447104472686, -0.0536985550218317
), group = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L), levels = c("Combination", "HSP90i"), class = "factor"), 
    sig_time = c(15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 
    15, 15, 15, 15, 15, 5, 5, 15, 15, 15, 15, 15, 5, 15, 15, 
    15, 5, 5, 5, 5, 5, 5, 5, 5, 5, 15, 5, 5, 5, 15, 15, 15, 15, 
    15, 15, 15, 15, 15, 5, 15, 15, 5, 15, 15, 15, 15, 15, 15, 
    15, 15, 15, 5, 15, 5, 15, 5, 15, 5, 5, 5, 5, 5, 5, 5, 5, 
    5, 15, 15, 5), log2FoldChange_time2 = c(-0.862944930337323, 
    -0.821495040691004, -0.53529566888596, -0.413727295318221, 
    -0.861649012400456, -0.625378856491763, -0.284667087341167, 
    -0.821156979407452, -0.378241572744422, -1.57115848331996, 
    -0.522190510192359, -0.293980540488672, -0.700568528879427, 
    -0.27374798241163, -0.586785638491822, -0.252186832534191, 
    NA, NA, -0.98050780193218, -0.994699036429169, -0.624973363057576, 
    -0.407625568750749, -1.59583773659725, NA, -0.592479302422313, 
    -0.796093452265886, -0.273890211216892, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, 0.300961097113397, NA, NA, NA, -1.35076109716791, 
    -1.41760508565058, -0.678320601935102, -0.428124639436631, 
    -0.646468799070835, -1.60305469405614, -0.375163597100949, 
    -0.829530226497803, -1.04428908102314, NA, -0.37771600704102, 
    -0.876340169852013, NA, -1.66098626656211, -0.531809442138136, 
    -0.284766529463218, -0.256262579295557, -0.668206465620295, 
    -0.445595052163749, -0.773664481955359, -1.28307559589586, 
    -1.00636175872241, NA, -0.412339465538486, NA, -0.936404181263657, 
    NA, 0.215874806209058, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    -0.449437636815058, -0.456447104472686, NA)), row.names = c(1L, 
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 115L, 
116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 
127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 
138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 
149L, 150L, 151L, 152L, 153L, 154L), class = "data.frame")

I managed to find a very ugly workaround to deal with this.

It seems that the figure starts with 3 colorscales. And, as soon as I trigger any hover/highlight event, 2 more colorscales are created, for a total of 5.

The default (viridis) colorscale seems to be always the 3rd one. Thus, I added a little JS snippet that hides its layer on window load:

```{js}
function code_default() {
    document.getElementsByClassName('infolayer')[0].getElementsByClassName('colorbar')[2].style.display = 'none'
}
window.onload = code_default;
...```

I’m still looking for an answer within plotly’s code, as this seems to be a very ad-hoc solution.