plotly / plotly/plotly.R

subplot() with bar and pie chart creates unnecessary attribute and warning

Aperta
#2,437 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I'm trying to make a single chart that has both a bar chart and a relevant pie using subplot(). Subplot is optimal because I'd like the users to be able to screenshot both charts at once. Here is the code:

library(dplyr)
library(plotly)

bar_info <- data.frame(
  Group = rep(c("first", "second", "third"), 2),
  values_monthly = c(100, 200, 300, 400, 500, 600),
  month = rep(c("April", "May"), each = 3) %>% as.factor()
)
pie_info <- group_by(bar_info, Group) %>%
  summarise(values_total = sum(values_monthly))

colors = c("red", "blue", "yellow")

bar_chart <- plot_ly(bar_info, type = "bar",
                     x = ~ month, y = ~ values_monthly, color = ~Group,
                     colors = colors)

pie_chart <- plot_ly(pie_info, type = "pie",
                     labels = ~Group, values = ~values_total,
                     marker = list(colors = colors),
                     # setting up pie to the right
                     domain = list(x = c(0.9, 1), y = c(0,1)),
                     showlegend = F
                     )
    
combined_chart <- subplot(bar_chart, pie_chart, nrows = 1, 
        widths = c(0.9, 0.1)) 

combined_chart

Now, the most important thing, the chart looks as it should.
However, it displays these warnings:

Warning messages:
1: Can't display both discrete & non-discrete data on same axis 
2: 'layout' objects don't have these attributes: 'NA'
Valid attributes include:
'_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'

How can I get rid of them? I've tried using shareX and shareY set to F or using add_trace for the pie, no help.
When I open the JSON with plotly_json(combined_chart), I can see that the layout object has a new, unneeded object NA2. This is probably related to the problem.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui l'esempio R riproducibile e ispeziona plotly_json(combined_chart), concentrandoti sul layout generato da subplot e sull'oggetto NA2 inatteso. Traccia il modo in cui subplot combina i layout del grafico a barre e del grafico a torta; il lavoro è completato quando l'esempio viene visualizzato senza nessuno dei due warning e senza l'attributo di layout non necessario.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
plotly, r
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.