Insert custom text in ggplot2

I have a ggplot graph that I would like to insert a custom line below 0 as “Inside” and above 0 as “Bleached”.

I'm doing it:

ggplot(z, aes(Date, Breach1/60, group=Jobs, label=c("Within SLA", "Breached SLA"))) + 
 geom_line(size=1) + 
 theme_bw() + ylab("Hours") + xlab("Date") + opts(title="Jobs") + 
 geom_hline(yintercept=0, color="red", size=2) + geom_text(hjust=0, vjust=3)

This seems to put text everywhere. I like to put one text above zero and one text below zero. Any ideas?

+5
source share
1 answer

You after annotation:

ggplot(z, aes(Date, Breach1/60, group=Jobs)) + 
 geom_line(size=1) + 
 theme_bw() + ylab("Hours") + xlab("Date") + opts(title="Jobs") + 
 geom_hline(yintercept=0, color="red", size=2) + 
 annotate("text", label = "Within SLA", x = 1, y = 2) +
 annotate("text", label = "Breached", x = 1, y = -2) 
+12
source

All Articles