繁体   English   中英

R plotly 带子图的饼图

[英]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.

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