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