Stackgroup with scatter and more than 1 axis not working properly?
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- R
- Estrellas
- 2.7k
- Forks
- 641
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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. :-)
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza ejecutando los dos ejemplos de R proporcionados y compara la salida cuando el segundo trace usa xaxis = "x2" y yaxis = "y2" con stackgroup. Sigue cómo add_trace y layout manejan los scatter traces apilados en varios ejes; el issue estará terminado cuando ambos grupos apilados se rendericen correctamente con los ejes secundarios, o cuando se documente la limitación compatible.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- plotly, r
- Área
- data-visualization
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100