subplot() with bar and pie chart creates unnecessary attribute and warning
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- plotly, r
- Domain
- data-visualization
Research direction
Run the reproducible R example and inspect plotly_json(combined_chart), focusing on the subplot-generated layout and the unexpected NA2 object. Trace how subplot combines the bar and pie chart layouts; done means the example renders without either warning and without the unnecessary layout attribute.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from plotly/plotly.R
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
save_image Error Open
Difficulty 3/5 1-2 days Newbie friendliness 52/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
easystats/performance#950 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
briandconnelly/airnow#9 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
OHDSI/CohortConstructor#774 ·