Multiple plotly pie charts in one row

前端 未结 2 2020
刺人心
刺人心 2021-01-22 08:42

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

2条回答
  •  广开言路
    2021-01-22 09:15

    There is new improved subplot functionality coming in the development version of plotly, but it appears the "bug" persists. I am not sure though how well it works with pie charts. I filed an issue on Github.

    # devtools::install_github('ropensci/plotly")
    
    library(plotly)
    ds_r <- data.frame(labels1 = c("Baseline", "DTC", "Detailing", "Flex"),
                       values1 = c(63.5, 8.5, 20.6, 7.4))
    
    ds_l <- data.frame(labels2 = c("Baseline"),
                       values2 = c(100))
    
    p <- plot_ly(ds_r, labels = ~labels1, values = ~values1, type = "pie", 
               showlegend = F) 
    
    p2 <- plot_ly(ds_l,labels = ~labels2, values = ~values2, type = "pie", 
               showlegend = F)
    
    subplot(p, p2, nrows = 1)
    

    For more detail on subplot, see the subplot vignette.

提交回复
热议问题