0

I have a barplot that looks like this:

enter image description here

I need to add the names to the top of the bars. But I only wish to label the names that are above the horizontal 0.5 line.

I can add labels as follows:

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

But this of course adds all values.

Cybernetic
  • 12,628
  • 16
  • 93
  • 132
  • @user20650 You probably mean `text(xx, ifelse(data$features> 0.5, data$features, 0), labels=ifelse(data$features> 0.5, data$features, ""))` – HubertL Oct 21 '15 at 01:19
  • using `ggplot2` you can use an `ifelse` in the label argument [similar solution](http://stackoverflow.com/a/15625149/4002530) – tospig Oct 21 '15 at 01:20

1 Answers1

1

What about :

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

HubertL
  • 19,246
  • 3
  • 32
  • 51