Solution to combine facetted legends breaks for continuous variable
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the two supplied R reproductions using plot_ly(), group_map(), and subplot(), then compare the discrete and continuous color cases. Trace how subplot combines traces and legends; done means continuous-variable legends are combined without breaking the facetted plot behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100