如何使饼图仅命名为前n位性能 [英] how to make a pie graph only name top n performance
问题描述
我在r中没有经常使用饼图,有没有办法制作饼图并只显示前10个带有百分比的名称?
I haven't been using pie graph a lot in r, is there a way to make a pie graph and only show the top 10 names with percentage?
例如,这是我的数据的简单版本:
For example, here's a simple version of my data:
> data
count METRIC_ID
1 8 71
2 2 1035
3 5 1219
4 4 1277
5 1 1322
6 3 1444
7 5 1462
8 17 1720
9 6 2019
10 2 2040
11 1 2413
12 11 2489
13 24 2610
14 29 2737
15 1 2907
16 1 2930
17 2 2992
18 1 2994
19 2 3020
20 4 3045
21 35 3222
22 2 3245
23 5 3306
24 2 3348
25 2 3355
26 2 3381
27 3 3383
28 4 3389
29 6 3404
30 1 3443
31 22 3465
32 3 3558
33 15 3600
34 3 3730
35 6 3750
36 1 3863
37 1 3908
38 5 3913
39 3 3968
40 9 3972
41 2 3978
42 5 4077
43 4 4086
44 3 4124
45 2 4165
46 3 4205
47 8 4206
48 4 4210
49 12 4222
50 4 4228
我想查看每个METRIC_ID分布的计数:
and I want to see the count of each METRIC_ID's distribution:
pie(data$count, data$METRIC_ID)
但是此图表标记了图形上的每个METRIC_ID,当我有100多个METRIC_ID时,它看起来就像一团糟.如何仅在图形上标记前n个(例如n = 5)METRIC_ID,并仅显示该n个METRIC_ID的计数?
But this Chart marks every single METRIC_ID on the graph, when I have over 100 METRIC_ID, it looks like a mess. How can I only mark the top n (for example, n=5) METRIC_ID on the graph, and show the count of that n METRIC_ID only?
谢谢您的帮助!
推荐答案
要禁止打印某些标签,请将它们设置为NA
.试试这个:
To suppress plotting of some labels, set them to NA
. Try this:
labls <- data$METRIC_ID
labls[data$count < 3] <- NA
pie(data$count, paste(labls))
这篇关于如何使饼图仅命名为前n位性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!