考虑来自https://plotly.com/r/sunburst-charts/的示例,可以将多个旭日形图绘制到一个图中:
library(plotly)
d1 <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/coffee-flavors.csv')
d2 <- read.csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/sunburst-coffee-flavors-complete.csv')
fig <- plot_ly()
fig <- fig %>%
add_trace(
ids = d1$ids,
labels = d1$labels,
parents = d1$parents,
type = 'sunburst',
maxdepth = 2,
domain = list(column = 0)
)
fig <- fig %>%
add_trace(
ids = d2$ids,
labels = d2$labels,
parents = d2$parents,
type = 'sunburst',
maxdepth = 3,
domain = list(column = 1)
)
fig <- fig %>%
layout(
grid = list(columns =2, rows = 1),
margin = list(l = 0, r = 0, b = 0, t = 0),
sunburstcolorway = c(
"#636efa","#EF553B","#00cc96","#ab63fa","#19d3f3",
"#e763fa", "#FECB52","#FFA15A","#FF6692","#B6E880"
),
extendsunburstcolors = TRUE)
fig
我遇到的问题是,我在隔离的函数中生成不同的旭日形图,我想随后将其绘制成一个图形。但是,此命令(以及plotly::subplot(p,p)
)似乎无效:
p <- plot_ly(
labels = c("Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"),
parents = c("", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"),
values = c(10, 14, 12, 10, 2, 6, 6, 4, 4),
type = 'sunburst'
)
fig <- plot_ly()
fig <- fig %>%
add_trace(
p,
domain = list(column = 0)
)
fig <- fig %>%
add_trace(
p,
domain = list(column = 1)
)
fig <- fig %>%
layout(
grid = list(columns =2, rows = 1),
margin = list(l = 0, r = 0, b = 0, t = 0))
fig
我在做什么错了?