I have a ggplot graph that I would like to insert custom string below 0 as "Within" and above 0 as "Breached".
I am doing this:
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 all over the place. I like to put one text above the zero and one text below the zero value. Any ideas?
The annotate() function allows to add all kind of shape on a ggplot2 chart. The first argument will control what kind is used: rect or segment for rectangle, segment or arrow.
If you want to annotate your plot or figure with labels, there are two basic options: text() will allow you to add labels to the plot region, and mtext() will allow you to add labels to the margins. For the plot region, to add labels you need to specify the coordinates and the label.
Use the title( ) function to add labels to a plot. Many other graphical parameters (such as text size, font, rotation, and color) can also be specified in the title( ) function. # labels 25% smaller than the default and green.
To customize the plot, the following arguments can be used: alpha, color, linetype, shape, size and fill.
You are after annotate:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With