How to place a text label on a plot located independently of the data?

I am trying to put a text label in ggplot, but I do not want to specify the label coordinates in the data coordinates, but use some coordinates that are not related to the data. I know the transformation trick:

xrng <- range(x)
yrng <- range(y)
plot <- plot + annotate("text",x = xrng[2], y = yrng[2], label="bla") # plot label on top right

But this does not work well for graphs with a logarithmic scale (and you need to do the conversion, which is not always as simple as in the example). Any ideas?

0
source share
1 answer
Graphs

ggplot2made with graphics grid, so you can use the commands gridto annotate the plot.

library('ggplot2')
library('grid')
qplot(rnorm(10))
grid.text('my label')

?grid.textprovides several ways to specify coordinates. Perhaps one of them will make sense in your case.

0

All Articles