在条件顶部添加标签。

时间:2015-10-20 23:39:03

标签: r plot

我有一个看起来像这样的条形图:

enter image description here

我需要将名称添加到栏的顶部。但我只想标记水平0.5线以上的名称。

我可以按如下方式添加标签:

 xx <- barplot(....)
 text(xx, data$features, labels=data$features, pos=3, offset=.5)

但这当然会增加所有价值。

1 个答案:

答案 0 :(得分:1)

怎么样:

set.seed(1)
y <- round(rnorm(10),1)
xx <- barplot(y)
yy <- y[y>.5]
xx <- xx[y>.5]
text(xx, yy, labels=yy, pos=3, offset=-1)

enter image description here