Stackgroup with scatter and more than 1 axis not working properly?
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
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. :-)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的两个 R 示例,并比较第二个 trace 使用 xaxis = "x2" 和 yaxis = "y2" 配合 stackgroup 时的输出。跟踪 add_trace 和 layout 如何处理跨多个坐标轴的堆叠 scatter trace;当两个堆叠组都能在次坐标轴上正确渲染,或已记录所支持的限制时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- plotly, r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100