由于您没有提供适当的样本数据,我将构建您描述的3步数据的两步版本。我会把它推广到你的概括。 (请注意,我将数据划分为类型和子类型,并构建一个三列数据集......您的最终版本将是相同的,但是具有“C”类型和一些新的子类型):
> df = data.frame(type = c("A", "A", "B", "B", "B", "B"), subtype = c("X1", "X2", "X1.a", "X1.b", "X2.a", "X2.b"), value = c(12, 36, 3, 9, 24, 12))
type subtype value
1 A X1 12
2 A X2 36
3 B X1.a 3
4 B X1.b 9
5 B X2.a 24
6 B X2.b 12
这里就是我如何做饼图与ggplot2
包:
library(ggplot2)
ggplot(df, aes(x = factor(1), y = value, fill = factor(subtype))) +
geom_bar(stat = "identity", width = 1) +
theme(legend.position = "none") +
scale_x_discrete(NULL, expand = c(0,0)) +
scale_y_continuous(NULL, expand = c(0,0)) +
coord_polar(theta = "y") +
facet_wrap(~type)
结果: