Label placing in ggplot2 using geom_text function in R

I'm designing some graphs within a function with ggPlot2 geom_text. It is a sequence of five graphs and, in each one, I want to place my label (my text) in the top right position. The problem is that I will constantly change my N and Y values (according to and input interval). X and Y coordinates will change, and even be out of scale. So how do I make the label placement fixed, let's say in the top right, in my graph?

Here's my code

parte.mac <- subset(dados, subset = (dados$Especie == 'C.macelaria' & dados$Temp >= minima & dados$Temp <= maxima))
  mac <- qplot(Temp, Tempo, data = parte.mac, color = Especie, main = 'C.macelaria', geom = c("point", "line"), add = T) +
    stat_smooth(method = 'lm', level = 0.99, alpha = 0.5, aes(group=1), color = 'blue') +
    geom_text(x = maxima, y = mean(range(dados$Tempo)), label =, parse = TRUE)

Please, help


Echoing the comment by @jazzuro, could you provide us with (your) reproducible data by running (don't send anything confidential!)


and pasting that with your question.

In the absence of your exact data, I'll echo @baptiste with a simple example using the "faithful" data file of the Old Faithful geyser eruptions:

p <- qplot(x=eruptions, y=waiting, data=faithful)

and then here is one example of an annotation:

p + annotate("text", x=3, y=40, label="Group 1") + annotate("text", x=4.5, y=60, label="Group 2")

Below is a second example, using arguments such as "min" and "max" for placement of the annotations:

p + annotate("text", x=min(faithful$eruptions), y=min(faithful$waiting), label="Group 1") + annotate("text", x=max(faithful$eruptions), y=max(faithful$waiting), label="Group 2")

If this doesn't help, remember to dput your data and paste into your question.

Need Your Help

Trying to edit my blog website

html css

I have this simple PHP website I am building, and I am having some issues getting somethings to work correct.

Achartengine on android - multiple Y axis

android achartengine

Having a hard time getting multiple Y axis to show up on a chart using achartengine on android. I have tried to copy what was done on the "Multiple Temperature Chart" demo here:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.