简体   繁体   English

在R Plotly中部署的子图

[英]Subplots deploying in R Plotly

I would be grateful if anyone could tell me how to specify domain layout to get same size pie charts in few columns. 如果有人能告诉我如何指定域布局以在几列中获得相同大小的饼图,我将不胜感激。 I have already found this example, however, I do not know what each argument of domain option mean and how do resize them and deploy properly, not many info in documentation. 我已经找到了这个示例,但是,我不知道domain option的每个参数的含义以及如何调整它们的大小并正确部署,文档中没有太多信息。

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))

Thank you. 谢谢。

The domain specifies the relative range of the complete plot in which the subplot is located. domain指定子图所在的完整图的相对范围。 The range is from 0 to 1 and 0 is the lowest/most left part. 范围是0到1,0是最低/最左部分。

In your case if you want to have three columns, you would need the x part of the domain would be a sliding window ( (0, 0.3), (0.35, 0.65), (0.7, 1) ) and the y part would be constant ( (0, 1) ). 在您的情况下,如果要具有三列,则需要将域的x部分设置为滑动窗口( (0, 0.3), (0.35, 0.65), (0.7, 1) ),而y部分将是常数( (0, 1) )。

在此处输入图片说明

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM