plotly / plotly/plotly.R

Stackgroup with scatter and more than 1 axis not working properly?

Aperta
#2,099 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 am doing a scatter plot with stackgroups. I would like to use the x2 and y2 axises. When I use the regular x and y axis, the result is correct. The data frame below is used. The first Plotly chunk is for the regular x and y axis behavior. The second one tries to use x2 and y2 but only the 2nd stack group is shown. I think this might be a bug.

library(datasets)

df <- mtcars[1:5,]
df$mpg <- 0
df$qsec <- df$qsec + runif(length(df$qsec),min=-3, max=5)
df$hp <- df$hp + runif(length(df$hp),min=-30, max=30)
df$names <- rownames(df)
rownames(df) <- NULL

df2 <-  mtcars[1:5,]
df2$names <- rownames(df2)
rownames(df2) <- NULL

df<- rbind(df,df2)

Below works but since the y axis range is quite different for qsec and hp, a second y axis is needed.

library(dplyr)
library(plotly)

plot_ly(type = "scatter",mode='none', width = 800, height=420) %>%
          add_trace(
                  mode = "lines",
                  stackgroup = "red",
                  orientation = "h",
                  x = df$mpg,
                  y = df$qsec,
                  line = list(color = "red"),
                  name = df$names) %>%
add_trace(
                  mode = "lines",
                  stackgroup = "blue",
                  orientation = "h",
                  x = df$mpg,
                  y = df$hp,
                  line = list(color = "blue"),
                  name = df$names)%>%
          layout(  xaxis =list(title="mpg", side = "bottom"),
                   yaxis =list(title="qsec",side = "left"))

Here, the following is tried.

library(dplyr)
library(plotly)

plot_ly(type = "scatter",mode='none', width = 800, height=420) %>%
          add_trace(
                  mode = "lines",
                  stackgroup = "red",
                  orientation = "h",
                  x = df$mpg,
                  y = df$qsec,
                  line = list(color = "red"),
                  name = df$names) %>%
add_trace(
                  mode = "lines",
                  stackgroup = "blue",
                  orientation = "h",
                  xaxis = "x2",
                  yaxis = "y2",
                  x = df$mpg,
                  y = df$hp,
                  line = list(color = "blue"),
                  name = df$names)%>%
          layout(  xaxis =list(title="mpg", side = "bottom"),
                   yaxis =list(title="qsec",side = "left")
                  ,yaxis2 = list(title = "hp", side = "right", overlaying = "y")
                  ,xaxis2 = list(title = "mpg", side = "top", overlaying = "y")
                  )  

I also tried using fill = "tozerox" and fill = "tozeroy" instead of orientation="h"|"v" but this doesn't work at all. Thank you in advance for taking a look. :-)

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

Inizia eseguendo i due esempi R forniti e confronta l’output quando il secondo trace usa xaxis = "x2" e yaxis = "y2" con stackgroup. Traccia il modo in cui add_trace e layout gestiscono gli scatter trace impilati su più assi; l’issue è completata quando entrambi i gruppi impilati vengono renderizzati correttamente con gli assi secondari, oppure quando viene documentata la limitazione supportata.

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.