[英]R plotly pie chart with subplots
我正在尝试制作一个R
plotly
pie chart
subplot
,其中包含两个饼图,每个饼图都有一个标题。 我遵循了本教程Subplots
下的示例,只绘制了三个饼图中的两个并为每个饼图添加了一个标题:
library(plotly)
library(dplyr)
fig <- plot_ly()
fig <- fig %>% add_pie(data = count(diamonds, cut), labels = ~cut, values = ~n, textinfo='label+percent', showlegend=F,
name = "Cut", domain = list(x = c(0, 0.4), y = c(0.4, 1))) %>%
layout(title="Cut")
fig <- fig %>% add_pie(data = count(diamonds, color), labels = ~color, values = ~n, textinfo='label+percent', showlegend=F,
name = "Color", domain = list(x = c(0.6, 1), y = c(0.4, 1))) %>%
layout(title="Color")
它看起来类似于使用plotly
subplot
function 时出现多个标题的问题(在此处讨论),但在这种情况下未明确调用子图,因此我不确定此处的等效解决方案是什么。
title
参数需要在trace
调用中:
fig <- plot_ly()
fig <- fig %>% add_pie(data = count(diamonds, cut), labels = ~cut, values = ~n, textinfo='label+percent', showlegend=F, title="Cut",
name = "Cut", domain = list(x = c(0, 0.4), y = c(0.4, 1)))
fig <- fig %>% add_pie(data = count(diamonds, color), labels = ~color, values = ~n, textinfo='label+percent', showlegend=F, title="Color",
name = "Color", domain = list(x = c(0.6, 1), y = c(0.4, 1)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.