plotly / plotly/plotly.R

Solution to combine facetted legends breaks for continuous variable

Offen
#2,112 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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("&nbsp;", 20),
                         paste("<b>", as.character(.y), "</b>"),
                         rep("&nbsp;", 20),
                         rep("\n&nbsp;", 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("&nbsp;", 20),
                         paste("<b>", as.character(.y), "</b>"),
                         rep("&nbsp;", 20),
                         rep("\n&nbsp;", 3)),
                       collapse = ""))) %>%
      layout(barmode = 'stack')
  }
  ) %>%
  subplot(nrows = NROW(.), margin = .05, shareX = T, shareY = T, titleY = T) 

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie damit, die beiden bereitgestellten R-Reproduktionen mit plot_ly(), group_map() und subplot() auszuführen, und vergleichen Sie anschließend die diskreten und kontinuierlichen Farbfälle. Verfolgen Sie, wie subplot Traces und Legenden kombiniert; als erledigt gilt die Aufgabe, wenn Legenden für kontinuierliche Variablen kombiniert werden, ohne das Verhalten facettierter Plots zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.