我试着先按父级,然后按级别为sunburst着色,这样parent1和parent2就分别为红色和蓝色,然后按级别向外渐变。
我似乎很接近使用sunburstcolorway
的布局,但它不太按级别着色。目前我的colorway输入是为每个观察指定的十六进制代码列表。
如果有一种方法可以为每个单独的部分指定颜色,那将是理想的。我似乎无法弄清楚,我对这方面非常陌生
library(plotly)
clin2 <- data.frame(
stringsAsFactors = FALSE,
ids = c("MGH","CU","MGH - WT",
"CU - WT","MGH - KDM","CU - KDM","MGH - G2032R",
"MGH - S1986F","MGH - D2033N","CU - L1951R/L2026M"),
labels = c("Gainor<br>et al. 2017",
"McCoach<br>et al. 2018","ROS1<br>Extrinsic",
"ROS1<br>Extrinsic","ROS1<br>Intrinsic","ROS<br>Intrinsic","G2032R",
"S1986F","D2033N","L1951R/<br>L2026M"),
parents = c(NA,NA,"MGH","CU","MGH",
"CU","MGH - KDM","MGH - KDM","MGH - KDM","CU - KDM"),
values = c(17L, 12L, 8L, 11L, 9L, 1L, 7L, 1L, 1L, 1L),
colors = c("#3182bd", "#e6550d", "#9ecae1", "#fdae6b", "#9ecae1",
"#fdae6b", "#deebf7", "#deebf7", "#deebf7", "#fee6ce")
)
clin2_plot <- plot_ly(clin2, ids = ~ids, labels = ~labels, parents = ~parents,
values = ~values, type = 'sunburst', branchvalues = 'total'
) %>% layout(sunburstcolorway = clin2$colors)
clin2_plot
先谢谢你了。
1条答案
按热度按时间jtw3ybtb1#
我编辑了你的代码,使其可复制。对我来说,它似乎是工作正常。我添加了一个黑色的痕迹-请检查以下内容: