Black Lives Matter. Please consider donating to Black Girls Code today.

Multiple plotly pie charts in one row

I am trying to arrange two pie charts in a single row using the subplot function from the plotly package but the resultant plot is not what I expect. I was able to do the same for line charts, etc but I am facing trouble plotting two pie charts in a single row. Following is the code that I have.

ds_r <- data.frame(labels = c("Baseline", "DTC", "Detailing", "Flex"),
                 values = c(63.5, 8.5, 20.6, 7.4))

ds_l <- data.frame(labels = c("Baseline"),
                 values = c(100))

plot_right <- plot_ly(ds_r, labels = labels, values = values, type = "pie") %>% 
  layout(title = "Sales - Decomposed")

plot_left <- plot_ly(ds_l, labels = labels, values = values, type = "pie") %>%
  layout(title = "Total Sales")

subplot(plot_left, plot_right, nrows = 2)

If you check the red boxes at the bottom of the image, there are two sets of axes which means there are two plots but they are probably getting overlapped or something.

I want the output to be two pie charts in a single row without any axes. Any help or direction?

1 Like

Pie chart subplots have a slightly different syntax, you can see an example here: https://plot.ly/r/pie-charts/#basic-pie-chart--subplots

The key is to use the domain parameter. Python examples at: https://plot.ly/python/pie-charts/ and I expect R will be analogous (although there are no R examples currently there).