Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label lines in a plot

Tags:

plot

r

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.

like image 403
Ruser Avatar asked Nov 16 '10 17:11

Ruser


People also ask

What is a label for a line plot?

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.

How do you label a plot?

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."


1 Answers

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'))
like image 64
Matthew Plourde Avatar answered Oct 14 '22 02:10

Matthew Plourde