Solution to combine facetted legends breaks for continuous variable
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
I am trying to use plotly to create facetted plots - I do this by using group_map() to create my plots robustly.
The solution I currently have works in reducing duplicated legend labels when using discrete variables for color/size/etc but fail to work for continuous variables. I assume this is do to each facetted plot potentially having different total ranges for the continuous variable.
library(tidyverse)
library(plotly)
city_list = unique(txhousing$city) %>%
sample(8)
##solution works for discrete labels
txhousing %>%
filter(month < 6,
city %in% city_list) %>%
group_by(month) %>%
group_map(~{
plot_ly(.x, x=~year, y = ~sales, color = ~city,legendgroup = ~city,type = "bar"
,showlegend = (.y == "1")
) %>%
layout(yaxis = list(
title = paste0(c(rep(" ", 20),
paste("<b>", as.character(.y), "</b>"),
rep(" ", 20),
rep("\n ", 3)),
collapse = ""))) %>%
layout(barmode = 'stack')
}
) %>%
subplot(nrows = NROW(.), margin = .05, shareX = T, shareY = T, titleY = T)
##solution fails to merge legends for continuous variable
txhousing %>%
filter(month < 6,
city %in% city_list) %>%
group_by(month) %>%
group_map(~{
plot_ly(.x, x=~year, y = ~sales, color = ~volume,legendgroup = ~volume,type = "bar"
,showlegend = (.y == "1")
) %>%
layout(yaxis = list(
title = paste0(c(rep(" ", 20),
paste("<b>", as.character(.y), "</b>"),
rep(" ", 20),
rep("\n ", 3)),
collapse = ""))) %>%
layout(barmode = 'stack')
}
) %>%
subplot(nrows = NROW(.), margin = .05, shareX = T, shareY = T, titleY = T)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用 plot_ly()、group_map() 和 subplot() 运行提供的两个 R 重现代码,然后比较离散颜色和连续颜色的情况。跟踪 subplot 如何组合轨迹和图例;完成的标准是:连续变量的图例能够合并,同时不破坏分面图的行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100