plotly / plotly/plotly.R

Long legend with horizontal orientation got truncated when converting ggplot object using ggplotly but it's fine when using plot_ly

未关闭
#848 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

ggplotly
主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

Hi all, as a work-around approah to display a very long multi-column legend, I tried to use the layout(legend = list(orientation = "h")).

Here is the data_frame I was working with:
image

When I first built a ggplot object and then used ggplotly to convert it, I got this:
p <- ggplot(df, aes_string("cluster", "mCH", fill="cluster"))
p <- p + geom_boxplot() + scale_fill_manual(values = colors2, name="Cluster") + theme_bw() + ggtitle("someGene")
p.ggplotly <- p %>% ggplotly(tooltip = c("cluster", "mCH", "density")) %>% layout(legend = list(orientation = "h"))
p.ggplotly

image

The legend had only one row and it just got out of the margin... But when I did a similar thing using plot_ly the legend was fine:

p.plotly <- plot_ly(df,x=~cluster, y=~mCH,type="box", color=~cluster, colors=colors2) %>% layout(legend=list(orientation = "h"))
p.plotly
image

And I thought this is somehow control by the layout, so I tried copying the layout from p.plotly to p.ggplotly:
p.ggplotly.bak <- p.ggplotly
p.ggplotly$x$layout <- p.plotly$x$layout
But the legend was still truncated...
p.ggplotly
image

However if I did it the other way around, I got a something like this:
p.plotly$x$layout <- p.ggplotly.bak$x$layout
p.plotly

image

The legend was displayed correctly with multiple rows(even though the position was not right, but I know how to adjust for that).

I'm not sure if this is because the ggplotly and plot_ly is inherently different, or there're other options that can controll this behavior (or this is just a bug?). Any idea? I somehow prefer to use ggplotly...

FYI, ggplot2 version is 2.2.1 and plotly version is 4.5.6.9000. Thanks!

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用报告中的 ggplot2 和 plotly R 示例复现该问题,将 ggplotly 转换与等效的 plot_ly 图表以及水平图例布局进行比较。跟踪转换和渲染行为,以确定 ggplotly 图例被截断的原因,然后验证较长的图例可以跨多行显示,同时不会破坏报告中所述的绘图行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。