2

I would like to rotate the label of a line representing a specific value on a distribution. Please consider the following data as example. It represents the results of a hypothetical test for 1000 students:

 e5a <- seq(30, 110, length = 1000)
 e5b <- dnorm(e5a, 70, 10)

I draw a plot, and on this plot I would indicate the result of Bob, that is 80:

plot_e5a <- xyplot(e5b ~ e5a, 
              type = "l",
              main = "Bob's score",
              panel = function(x, ...){
                      panel.xyplot(x, ...)
                      panel.abline(v = c(70, 80), lty = c(1, 2))
                      panel.text(lab = c("Mean", "Bob"), x = c(70, 80), y = 0.037, 
            adj = c(0.4, 0), cex = 1.5)
              })

enter image description here

I would like to rotate the labels "mean" and "bob" on the two vertical lines of the graph, hence I tried to rotate the text with the argument rot, that I usually use for Lattice plots:

panel.text(lab = c("Mean", "Bob"), x = c(70, 80), y = 0.037, 
            adj = c(0.4, 0), cex = 1.5, rot = 90)

Unfortunately, it had no effect. I tried las too, without effect.

Community
  • 1
  • 1
Worice
  • 3,847
  • 3
  • 28
  • 49
  • 3
    Are you looking for the `srt` argument? For example: `panel.text(lab = c("Mean", "Bob"), x = c(70, 80), y = 0.037, adj = c(0.4, 0), cex = 1.5, srt = 90)` – Jota Mar 30 '16 at 20:29
  • It works perfectly, thank you. Can you suggest me a resource to learn the difference between `rot`, `srt`, that is, when should I use the first or the second. – Worice Mar 30 '16 at 20:38
  • 3
    The help page for [`?xyplot`](https://stat.ethz.ch/R-manual/R-devel/library/lattice/html/xyplot.html) has information about `rot` which is passed in a list to the `scales` argument. It is the "Angle (in degrees) by which the axis labels are to be rotated." `srt` is a little harder to track down, but you can find information about it by starting with `?panel.text`, which will tell you to look to the corresponding base function `text`, which points to the graphical parameters help page: [`?par`](https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/par.html) – Jota Mar 30 '16 at 20:46

0 Answers0