问题
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.
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.
回答1:
The domain
specifies the relative range of the complete plot in which the subplot is located. The range is from 0 to 1 and 0 is the lowest/most left part.
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)
).
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))
来源:https://stackoverflow.com/questions/46013559/subplots-deploying-in-r-plotly