2017-09-02 43 views
0

如果有人能告訴我如何指定 域佈局來獲得幾列相同大小的餅圖,我將不勝感激。 我已經找到了這個例子,但是,我不知道域選項的每個參數意味着什麼,以及如何調整它們的大小並正確部署,文檔中沒有很多信息。部署在R Plotly的子圖

plot_ly() %>% 
    add_pie(data = count(diamonds, cut), labels = ~cut, values = ~n, 
      name = "Cut",domain = list(x = c(0.4, 0.9), y = c(0.4, 1)),hole = 0.6) %>% 
    add_pie(data = count(diamonds, color), labels = ~cut, values = ~n, 
      name = "Color", domain = list(x = c(0.4, 0.4), y = c(0.4, 1)),hole = 0.6) %>% 
    add_pie(data = count(diamonds, clarity), labels = ~cut, values = ~n, 
      name = "Clarity", domain = list(x = c(0.4, 0.001), y = c(0.4, 1)),hole = 0.6) %>% 
    layout(showlegend = F,autosize=TRUE, 
     xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), 
     yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE)) 

謝謝。

+0

的可能的複製[Plotly域變量說明(多個圖)](https://stackoverflow.com/questions/42637341/plotly-domain-variable-explained-multiple-graphs) –

回答

0

domain指定了子圖所在的完整圖的相對範圍。範圍從0到1,0是最低/最左邊的部分。

在你的情況,如果你想有三列,則需要域的x部分將是一個滑動窗口((0, 0.3), (0.35, 0.65), (0.7, 1))和y部分將是常數((0, 1))。

enter image description here

library (plotly) 
library(magrittr) 
library(dplyr) 
plot_ly() %>% 
    add_pie(data = count(diamonds, cut), labels = ~cut, values = ~n, 
      name = "Cut",domain = list(x = c(0.0, 0.30), y = c(0, 1)),hole = 0.6) %>% 
    add_pie(data = count(diamonds, color), labels = ~cut, values = ~n, 
      name = "Color", domain = list(x = c(0.35, 0.65), y = c(0, 1)),hole = 0.6) %>% 
    add_pie(data = count(diamonds, clarity), labels = ~cut, values = ~n, 
      name = "Clarity", domain = list(x = c(0.7, 1), y = c(0, 1)),hole = 0.6) %>% 
    layout(showlegend = F,autosize=TRUE, 
      xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), 
      yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))