You can use par ('usr'). It gives you the current coordinates of the plot. Really useful if you want text in a certain area of each subplot and you don't know the coordinates in advance (e.g. a histogram). The output looks like:
par('usr')
[1] -0.28 7.28 -3.00 78.00
wherein the x min is the first member of the list, the x max is the second, the y min is the third, and the y max is the fourth. You can treat par('usr') like a vector in R and if you want it to be in the top left you can do, say:
text(par('usr')[1]+2,.9*par('usr')[4],labels="blahblah")
From this it will be plotted in the upper 10% of the plot and +2 from the leftmost coordinate of the plot space. Of course you can adjust this, but that would be top left more or less.
Using this code for my data:
y <- rnorm(100)
z <- rnorm(100)
par(mfrow = c(1,2))
hist(y, breaks = 30)
text(.8 * par('usr')[2], .9 * par('usr')[4], labels = paste("mean:", round(mean(y), 2)))
text(.8 * par('usr')[2], .86 * par('usr')[4], labels = paste("median:", round(median(y), 2)))
hist(z, breaks = 30)
text(.8 * par('usr')[2], .9 * par('usr')[4], labels = paste("mean:", round(mean(z), 2)))
text(.8 * par('usr')[2], .86 * par('usr')[4], labels = paste("median:", round(median(z), 2)))
mtext("distributions", side = 3, line = -2, outer = TRUE, col = 2) # added mtext to show how I would use it to create a title
I got this image:
