Reputation: 5540
I plot the following data frame (x
):
Position S1 S2 S3 S4
1 53 0.0000 0.5000 0.0000 0.2000
2 54 0.2000 0.5000 0.0000 0.0000
3 55 0.0000 0.5000 0.1000 0.0000
4 56 0.0000 0.0000 0.1000 0.4000
5 57 0.2000 0.0000 0.0000 0.0000
6 58 0.0000 0.0000 0.2000 0.0000
7 59 0.3000 0.0000 0.1000 0.0000
8 60 0.0000 0.4000 0.0000 0.6000
9 61 0.0000 0.0000 0.0000 0.5000
10 62 0.0000 0.0000 0.1000 0.6000
and add text using
plot(x$S1, type="h")
text(x$S1)
However, I only want text for values in the table above a threshold. So I do the following:
plot(x$S1, type="h")
y = x$S1
y[y<0.2] = NA
text(y)
This works as I would like it to. However, ideally, I would like the x-axis values to be x$Position
, rather than just incrementing from 1. I can plot this with:
plot(x$Position, x$S1, type="h")
but the text labels still show the incrementing values, not the values of x$Position
. I have tried a number of approaches to solve this, but have not had success.
How can I include x$Position
values as text on the graph, but only for x$S1
values above a threshold?
Upvotes: 2
Views: 115
Reputation: 6207
Do you want this?:
plot(x$Position, x$S1, type="h")
text(x$Position,y,labels=x$Position)
Upvotes: 1