下面的代码通过 AlertTypeId 生成一个饼图。但是,AlertTypeId 太多了,我想将饼图中的切片数量限制为 X 最频繁的警报,其余的进入“其他”类别。我怎么能用ggplot2做到这一点?
a = c(0, 0, 0, 1, 2, 3, 3, 3)
b = c(1, 1, 0, 0, 1, 1, 1, 1)
c = c(1, 4, 2, 2, 2, 1, 1, 3)
sa2 = data.frame(WeekOfYear = a, UrgentState = b, AlertTypeId = c, IsUrgent = b)
ggplot(sa2, aes(x = factor(1), fill = factor(AlertTypeId))) +
geom_bar(width = 1) +
coord_polar(theta = "y")