plotly / plotly/plotly.R

subplot() with bar and pie chart creates unnecessary attribute and warning

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

还没有人认领这个 Issue。

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

描述

I'm trying to make a single chart that has both a bar chart and a relevant pie using subplot(). Subplot is optimal because I'd like the users to be able to screenshot both charts at once. Here is the code:

library(dplyr)
library(plotly)

bar_info <- data.frame(
  Group = rep(c("first", "second", "third"), 2),
  values_monthly = c(100, 200, 300, 400, 500, 600),
  month = rep(c("April", "May"), each = 3) %>% as.factor()
)
pie_info <- group_by(bar_info, Group) %>%
  summarise(values_total = sum(values_monthly))

colors = c("red", "blue", "yellow")

bar_chart <- plot_ly(bar_info, type = "bar",
                     x = ~ month, y = ~ values_monthly, color = ~Group,
                     colors = colors)

pie_chart <- plot_ly(pie_info, type = "pie",
                     labels = ~Group, values = ~values_total,
                     marker = list(colors = colors),
                     # setting up pie to the right
                     domain = list(x = c(0.9, 1), y = c(0,1)),
                     showlegend = F
                     )
    
combined_chart <- subplot(bar_chart, pie_chart, nrows = 1, 
        widths = c(0.9, 0.1)) 

combined_chart

Now, the most important thing, the chart looks as it should.
However, it displays these warnings:

Warning messages:
1: Can't display both discrete & non-discrete data on same axis 
2: 'layout' objects don't have these attributes: 'NA'
Valid attributes include:
'_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'

How can I get rid of them? I've tried using shareX and shareY set to F or using add_trace for the pie, no help.
When I open the JSON with plotly_json(combined_chart), I can see that the layout object has a new, unneeded object NA2. This is probably related to the problem.

贡献指南

打开贡献指南

从这里开始

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

调研方向

运行可复现的 R 示例并检查 plotly_json(combined_chart),重点关注由 subplot 生成的 layout 以及意外的 NA2 对象。跟踪 subplot 如何组合柱状图和饼图的 layout;当示例渲染时既没有两个警告中的任何一个,也没有不必要的 layout 属性,即表示完成。

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

评估

技术栈
plotly, r
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

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