I am plotting two lines using
plot(x, y, type = "l", color = "red")
and
points(x2, y2, type = "l", color = "blue")
I want to be able to add a label next to each line (instead of a legend). I am pretty sure it is possible using the package in http://directlabels.r-forge.r-project.org/.
Yet, I don't find an easy way of doing that.
A line plot consists of a horizontal line which is the x-axis with equal intervals. It is important for a line to plot to have a title and a label of the x-axis to provide the reader an overview of what is being displayed. Also, line plots must have legends to explain what is being measured.
To properly label a graph, you should identify which variable the x-axis and y-axis each represent. Don't forget to include units of measure (called scale) so readers can understand each quantity represented by those axes. Finally, add a title to the graph, usually in the form "y-axis variable vs. x-axis variable."
Instead of using locator(), you could also just make the label coordinates a function of your data. For example, piggy backing on Roman's demo:
text(x=rep(max(x)+3, 2), y=c(mean(y), mean(y2)), pos=4, labels=c('black line', 'red line'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With