plotly / plotly/plotly.R

Provide more semantics around customization of the colorscale

Aberta
#920 2 comentários 2 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

enhancement
Linguagem predominante
R
Estrelas
2.7k
Forks
641
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

Heatmap does not use all the colors specified in the colors argument when data passed to z value has skewed distribution. Here is a small example to illustrate the problem.

library(plotly)
library(RColorBrewer)

# create a dataframe where z has a skewed distribution
set.seed(1)
df = data.frame(x = rep(1:50, 20) , y = rep(1:20,each =50), z = rgamma(1000, 2, 0.5))

# check distribution of z 
plot_ly(data = df, x = ~z, type = "histogram")%>% 
    layout(title = "histogram of z")  

# original heatmap
# pass the column z with screwed distribution to z argument
plot_ly(data=df, x=~x, y=~y, z=~z, type="heatmap",  
        colors = "Spectral") %>% 
    layout(title = "original heatmap")

I currently work around the issue by creating a new variable according to the quantiles of the original variable, and pass it to the z argument.

# some data processing work 
# find unique quantiles of z 
quantiles = unique(quantile(df$z, seq(0,1,0.1)))

# create a dummy column z1 of discrete values using the quantiles as cut off
# the ideas is to arrage the data to subgroups of roughly the same size 
df$z1= cut(df$z, breaks =  c(quantiles[1]-1,quantiles[-1]), right = TRUE, labels = FALSE)

# check distribution of z1 
plot_ly(data = df, x = ~z1, type = "histogram")%>% 
    layout(title = "histogram of z1")

# new heatmap 
# passes the new column z1 to z argument 
plot_ly(data=df, x=~x, y=~y, z=~z1, type="heatmap",  
        # make sure hovering over displays original z
        text =~z, hoverinfo = "text", 
        # use the color palettes from RColorBrewer, 
        # or your customized colorscale
        colors = "Spectral",  
        # map the label of the colorbar back to the quantiles
        colorbar=list(tickmode="array", tickvals = 1:(length(quantiles)-1), ticktext = round(quantiles,2)[-1], title = "z")) %>% 
layout(title = "new heat map")

Here is the link to the heatmaps before and after data processing. The new heatmap picks up more colors from the "Spectral" palette to differentiate between smaller values.
https://i.stack.imgur.com/TymlR.png

I would like to see features in plotly to force heatmap use all the user specified colors.

Thanks!

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Reproduza o exemplo fornecido de heatmap em R com os valores z distribuídos segundo uma gamma assimétrica e compare-o com a solução alternativa baseada em quantis. Comece rastreando o argumento colors de heatmap e determinando a semântica pretendida para usar todas as cores especificadas; a definição de concluído deve incluir um comportamento definido para distribuições assimétricas e um exemplo verificado.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
r
Domínio
data-visualization
Tipo de issue
Funcionalidade
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.