0

I have plotly pie chart, and some times the title overlaps with labels. Though I know how to manually rotate the chart, I'd like to add a zoom in/zoom out mode bar button for users to zoom out if the chart ever overlaps. This button option is not visible by default for pie charts.

However, when I follow the instructions here about adding modebarbuttons, it doesn't work. I'd like all the default buttons that come with a pie chart + the zoom in/out.

library(dplyr)
library(plotly)

pie_chart_margins <- list(
  l = 40,
  r = 40,
  b = 30,
  t = 60,
  pad = 4
)

data <- tibble(category = c("Big Project", "Work as Usual", "Other"),
               score = c(75.4, 3.4, 1.2))

pie_chart_text_format <- list(
  family = "Arial",
  size = 11)
my_colors <- c("#CA001B", "#1D28B0", "#D71DA4", "#00A3AD", "#FF8200", "#753BBD", "#00B5E2", "#008578", "#EB6FBD", "#FE5000", "#6CC24A", "#D9D9D6", "#AD0C27", "#950078")


fig <- plot_ly(type='pie', labels=data$category , values=data$score, 
               textinfo='label+percent', marker = list(colors = my_colors), insidetextfont = list(color = '#FFFFFF'),
               insidetextorientation='horizontal') %>%
  config(modeBarButtonsToAdd = list(list("zoomIn2d"), list("zoomOut2d")))



fig %>% layout(font=pie_chart_text_format, showlegend = FALSE, title = list(text = "Required Project Capacity\nby Type",
                                                                            font = "Arial"), margin = pie_chart_margins)
J.Sabree
  • 2,280
  • 19
  • 48
  • "I'd like all the default buttons that come with a pie chart + the zoom in/out." The buttons you're seeing are the default buttons for the piechart. `zoomIn2d` and `zoomOut2d` can only be removed (irrespective of chart type) ([link](https://plotly.com/r/reference/layout/#layout-modebar)). [Related post](https://stackoverflow.com/a/58986421/9098350). – 5eb Aug 05 '21 at 07:05
  • @BasvanderLinden , when I run the above code or the same code without the line without the modebarbutton line, there’s no zoom buttons for pie charts. – J.Sabree Aug 05 '21 at 11:08
  • That's what I'm saying. Those buttons don't come with pie charts. – 5eb Aug 05 '21 at 11:13
  • @BasvanderLinden , is there no way to override that default then? When would I ever use the modeBarButtonsToAdd() command of some buttons just aren’t allowed no matter what? – J.Sabree Aug 05 '21 at 11:19

0 Answers0