[英]plotly R API, is it possible to have subplots for pie charts?
I'm hoping to subplot two pie charts with plotly's R API. 我希望使用plotly的R API对两个饼图进行子图绘制。 However, it doesn't seem to work.
但是,它似乎不起作用。
library(plotly)
ds <- data.frame(labels = c("A", "B", "C"),
val1 = c(10, 40, 60),
val2 = c(20,40, 50))
p1 <- plot_ly(ds, labels = labels, values = val1, type = "pie")
p2 <- plot_ly(ds, labels = labels, values = val2, type = "pie")
subplot(p1, p2, margin=0.05)
Thank you for your help. 谢谢您的帮助。
I'll try and answer. 我会尽力回答。 For pie charts using
plot_ly()
the regular domain parameter used inside layout()
doesn't work. 对于使用
plot_ly()
的饼图,在layout()
内部使用的常规域参数不起作用。 You'll need to specify the domains inside the plot_ly()
and add_trace()
calls like so: 您需要像下面这样指定
plot_ly()
和add_trace()
调用内的域:
library(plotly)
df <- data.frame(labels1 = LETTERS[1:5], values1 = sample(100:200, size = 5),
labels2 = LETTERS[6:10], values2 = sample(100:200, size = 5))
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) %>%
layout(title = "Pie chart - subplot")
Hope this helps... 希望这可以帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.