【发布时间】:2019-08-11 06:54:58
【问题描述】:
我是 R 新手,我会直接在 cmets 中问这个问题,但我还没有声誉:D
基本上,我想做一个像 dmp 这样的旭日形图,在这个线程中建议:How to make a sunburst plot in R or Python?
但是,我的数据框看起来更像这样:
df <- data.frame(
'level1'=c('a', 'a', 'a', 'b', 'b', 'b', 'c', 'c'),
'level2'=c('AA', 'BB', 'CC', 'AA', 'BB', 'CC', 'AA', 'BB'),
'value'=c(12.5, 12.5, 75, 50, 25, 25, 36, 64))
所以当我按如下方式绘制旭日形图时:
ggplot(df, aes(y=value)) +
geom_bar(aes(fill=level1, x=0), width=.5, stat='identity') +
geom_bar(aes(fill=level2, x=.25), width=.25, stat='identity') +
coord_polar(theta='y')
ggplot 将 level2 组合在一起(因此将所有 AA 添加在一起,然后将所有 BB 和所有 CC 添加在一起),而不是将每个级别都留在其 level1 中。我该如何防止呢?
非常感谢您,
纳特
【问题讨论】:
标签: r ggplot2 data-visualization sunburst-diagram