0

I'm confused as how to add text in xyplot. Given the toy example below, I'd like to add the text "A", "B", "C" at the far right of the tips of YA, YB, and YC, respectively. I reformatted my data into a data.frame so it mimics my actual dataset. Any tips are greatly welcome

X = seq(1,100,length.out=5)
YA = 4*X + 10
YB = 2*X-5
YC = 0.5*X + 100

Xs = rep(X,3)
Y = c(YA,YB,YC)
index = as.factor(c(rep(1,5),rep(2,5),rep(3,5)))
Mat = data.frame(index,Xs,Y)
levels(Mat$index)=c("A","B","C")

xyplot(Y~Xs,data=Mat,group=index,col=c("blue","red","black"),type="l")
John Paul
  • 12,196
  • 6
  • 55
  • 75
stats134711
  • 624
  • 1
  • 5
  • 15
  • 1
    This should probably be marked as a duplicate question. The answer to this question, [How to label panels in lattice](http://stackoverflow.com/questions/8508269/how-to-label-panels-in-lattice), provides a solution. You'll need to calculate the position of the end of each line, but that doesn't seem too difficult. You may also be able to use the `text` function, as described in this answer: [How can i label points in this scatterplot?](http://stackoverflow.com/questions/13229546/how-can-i-label-points-in-this-scatterplot) – Mars Dec 06 '14 at 19:16
  • You're right. Thank you for pointing me to that link. It works now! – stats134711 Dec 06 '14 at 20:40
  • the `directlabels` package is often useful in such situations – baptiste Dec 14 '14 at 19:04
  • http://www.magesblog.com/2014/02/adding-labels-within-lattice-panels-by.html explains an approach to your problem. – user2030503 Mar 29 '15 at 17:36

0 Answers0