Provide more semantics around customization of the colorscale
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- R
- Star
- 2.7k
- Fork
- 641
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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!
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện ví dụ heatmap trong R được cung cấp với các giá trị z có phân phối gamma lệch và so sánh với giải pháp thay thế dựa trên quantile. Bắt đầu bằng cách lần theo đối số colors của heatmap và xác định ngữ nghĩa dự kiến khi sử dụng tất cả các màu đã chỉ định; tiêu chí hoàn thành cần bao gồm hành vi được định nghĩa cho các phân phối lệch và một ví dụ đã được xác minh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- r
- Lĩnh vực
- data-visualization
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100