Reputation: 69
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
Upvotes: 1
Views: 560
Reputation: 389
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.
Upvotes: 1