假设我用library(plotly)
制作了以下条形图(右侧的空白处是有意的):
library(dplyr)
library(plotly)
library(tidyr)
d <- tibble(cat = LETTERS[1:3],
val = c(25, 10, 30),
total = 40)
(bars <- d %>%
mutate(remaining = total - val) %>%
pivot_longer(cols = c(val, remaining)) %>%
plot_ly(x = ~ value, y = ~ cat,
type = "bar",
orientation = 'h', color = ~ name,
colors = c("#440154FF", "#FDE725FF")) %>%
layout(xaxis = list(title = NA, range= c(0, 60)),
yaxis = list(title = NA),
showlegend = FALSE,
barmode = "stack"))
现在我想在x == 50
和相应的y位置插入以下饼图:
pies <- d %>%
rowwise() %>%
group_map(~ plot_ly(.x) %>%
add_pie(values = ~ c(val, total - val),
marker = list(colors = c("#440154FF", "#FDE725FF"))))
预期的结果如下所示(通过手动将饼粘贴到条形图中来完成):
理想情况下,xa轴将只跨越到40,并且在馅饼下面没有可见的轴.
注:我想在这个reprex, colored颜色 也混乱,我将如何调整 colored颜色 在饼图,使他们匹配的 colored颜色 在条形图?