使用 Plotly

时间:2021-02-03 09:39:20

标签: r r-plotly

我已经用 plotly 在同一个图上绘制了这两个饼图。您可以在下面看到代码和我的数据:

suppressPackageStartupMessages(invisible(
                             lapply(c("plotly", "dplyr"), require, character.only = TRUE)))
                           
                           Share <- structure(list(Y = c(2018, 2018, 2019, 2019), 
                                                   Categorie = c("Before","After", "Before","After"), 
                                                   Share = c(1.0,99., 3, 97)), 
                                              row.names = c(NA,-4L), class = c("tbl_df", "tbl", "data.frame")) 
                           
p <- plot_ly() %>%
                             add_pie(data=Share, labels = ~Categorie , values = ~Share, hole = 0.6,
                                     name = "fig1", domain = list(x = c(0, 0.4), y = c(0.4, 1))) %>%
                             add_pie(data=Share, labels = ~Categorie , values = ~Share, hole = 0.6,
                                     name = "fig2", domain = list(x = c(0.6, 1), y = c(0.4, 1)))  %>%
                             layout(title = "Donut sub-plots", showlegend = FALSE,
                                    font=list(family="sans serif", color="#000"),
                                    plot_bgcolor="#f0f0f0",
                                    legend = list(orientation = 'h',font=list(size=28)),
                                    xaxis = list(title="", showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
                                    yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
                           p

enter image description here

你可以从图中看到两个饼图都在图像的上部。但我想要两个相等的饼图,它们的位置在图像的中心。那么有人可以帮助我如何在情节中做到这一点吗?

0 个答案:

没有答案
相关问题