plotly / plotly/plotly.R

Provide more semantics around customization of the colorscale

未关闭
#920 2 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement
主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

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!

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用偏斜的 gamma 分布 z 值复现所提供的 R heatmap 示例,并将其与基于分位数的变通方案进行比较。首先跟踪 heatmap 的 colors 参数,并确定使用所有指定颜色时预期的语义;完成标准应包括针对偏斜分布的明确定义行为以及一个经过验证的示例。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。