Long legend with horizontal orientation got truncated when converting ggplot object using ggplotly but it's fine when using plot_ly
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- R
- Star
- 2.7k
- Fork
- 641
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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:

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

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

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

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

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!
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện vấn đề bằng cách sử dụng các ví dụ ggplot2 và plotly trong R trong báo cáo, so sánh quá trình chuyển đổi ggplotly với biểu đồ plot_ly tương đương và bố cục chú giải theo chiều ngang. Theo dõi hành vi chuyển đổi và kết xuất để xác định lý do chú giải ggplotly bị cắt ngắn, sau đó xác minh rằng các chú giải dài được hiển thị trên nhiều hàng mà không làm thay đổi hành vi của biểu đồ được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- r
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100