在饼图中保留值和标签顺序

时间:2014-05-26 18:18:14

标签: r graph plot pie-chart

我想绘制一个饼图,其中必须保留值和标签的顺序。我怎么能生产它?

默认情况下,R可以按字母顺序和顺时针顺序控制。 另外,我想通过添加将一个点连接到另一个图表的箭头来添加更多信息到图表,例如从ABCZXR,是否可能?

# Simple Pie Chart
slices <- c(12,11,11,8,6,2,5,3)
lbls <- c("ABC", "DEF", "GPH", "ZXR", "O", "MN", "TS", "ZY")
pie(slices, labels = lbls, main="ranking disk")

谢谢, 伊芙

1 个答案:

答案 0 :(得分:2)

以下将创建一个饼图,其中的标签按照您提出的顺序排列,从12点钟开始顺时针方向:

pie(slices, labels = lbls, clockwise=TRUE, init.angle=90, main="ranking disk")

您可以调整clockwiseinit.angle参数。

不幸的是,pie不会返回标签或切片的坐标,但如果您根据需要调整坐标,则可以手动添加箭头:

arrows(.6,.6,-.6,-.4)

pie

然而,你知道饼图是提供信息的可怕方式,对吧?帮助页面?pie的以下部分非常值得引用:

 Pie charts are a very bad way of displaying information.  The eye
 is good at judging linear measures and bad at judging relative
 areas.  A bar chart or dot chart is a preferable way of displaying
 this type of data.

 Cleveland (1985), page 264: “Data that can be shown by pie charts
 always can be shown by a dot chart.  This means that judgements of
 position along a common scale can be made instead of the less
 accurate angle judgements.” This statement is based on the
 empirical investigations of Cleveland and McGill as well as
 investigations by perceptual psychologists.