plotly / plotly/plotly.R

Grouped boxplot data not centred on xaxis ticks, looses boxgap argument, and wont resize with subplots

Aperta
#1,484 5 commenti 6 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

Hi @cpsievert!

Here after your Shiny webinar, great stuff!

I'm having issues with the boxplot data aligning with x-axis tick marks in subplots. Please see below:

library (data.table)
library (stringr)
library (plotly)
# some setup:
get_plot_title = function(this.plot.title, y.pos = 1, y.shift = 0){
  list(text = sprintf ("<b>%s</b>", this.plot.title), yshift = y.shift
       , xref = "paper", yref = "paper", yanchor = "center", xanchor = "center", align = "center"
       , x = 0.5, y = y.pos, showarrow = FALSE, font = list (size = 16, family = "Arial")
  )} 

generate_panel = function(dat, trace.name){
  my.plot = 
    plot_ly(dat, type = "box"
            , x= ~get(x_var), y= ~get(y_var), color = ~get(color_var)
            , whiskerwidth = 0.1
            , boxpoints = F
    )   %>% 
    layout(boxmode = "group", boxgroupgap = 0.1, boxgap = 0.15
           , plot_bgcolor = "#F5F5F5"
           , annotations = get_plot_title(trace.name, y.shift = 20)
           , xaxis = list(title = "", tickfont = list(size = 14, family = "Arial")
                          , tickmode = "linear", ticks = "outside")
           , yaxis = list(title = sprintf("<b>%s</b>", y_var), titlefont = list (size = 16, family = "Arial"))
           ) 
  my.plot #return
}

x_var = "cut"
y_var = "price"
color_var = "color" 
X_panel_var = "clarity"
test.dat = ggplot2::diamonds %>% setDT
Without subplots, everything looks great:
generate_panel(test.dat, trace.name = "all")

image

Adding two horizontal subplots:
test.dat[, get(X_panel_var) %>% levels][1:2] %>% 
  lapply(function(this.panel.var){
    generate_panel(dat = test.dat[this.panel.var, on = X_panel_var], trace.name = this.panel.var)
  }) %>% 
  subplot(shareY = T, shareX = F, titleX = F, nrows = 1, which_layout = 1, margin = 0.01)

Boxplot groups shift off the centre of the xaxis ticks, and the boxgap argument becomes irrelevant:
image

Enlarging this plot does not work at all (cuts off the data at the original subplot width and height, yikes!):

image

Interestingly, with 3 horizontal subplots, the middle plot data is centered around ticks, but the outer plots are even further away (and the boxgaps are worse):
test.dat[, get(X_panel_var) %>% levels][1:3] %>% 
  lapply(function(this.panel.var){
    generate_panel(dat = test.dat[this.panel.var, on = X_panel_var], trace.name = this.panel.var)
  }) %>% 
  subplot(shareY = T, shareX = F, titleX = F, nrows = 1, which_layout = 1, margin = 0.01) 

image

Just wondering if you have any ideas / suggestions?

Thank you!

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

Riproduci l'esempio R diamonds fornito usando generate_panel e subplot con due e tre pannelli orizzontali. Esamina innanzitutto i punti di ingresso per il layout dei boxplot e il ridimensionamento di subplot. Il lavoro è completato quando i box raggruppati rimangono centrati sui tick dell'asse x, boxgap viene rispettato e i subplot ingranditi mostrano tutti i dati.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.