Multiple plotly pie charts in one row

拜拜、爱过 提交于 2019-12-02 01:58:32
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))
df <- cbind(ds_r, ds_l)

plot_ly(df, labels = labels1, values = values1, type = "pie", 
        domain = list(x = c(0, 0.4)), showlegend = F) %>% 

  add_trace(labels = labels2, values = values2, type = "pie", 
            domain = list(x = c(0.6, 1)), showlegend = F)

I would add the picture, but plotlies are generally large files.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!