1

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 = mac.sm, parse = TRUE)

Please, help

3
  • 2
    Could you provide a reproducible / minimum data? Commented Aug 20, 2015 at 23:41
  • typically this works, p+ annotate("text", y=Inf, x=Inf, label="here"), you may need to adjust vjust/hjust Commented Aug 21, 2015 at 0:03
  • hi baptiste and jazzurro, my temp data ranges from 10 - 50 and my tempo data ranges form 240 - 180 Commented Aug 21, 2015 at 0:19

1 Answer 1

1

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

dput(parte.mac)

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:

data(faithful)
head(faithful)
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Woodstock, it was the annotate function I was looking for! I got that going now, thaks a lot! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.