7

我有一个 ggplot 图,我想将自定义字符串插入 0 以下作为“内部”,将 0 以上作为“违反”。

我正在这样做:

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)

这似乎把文字放在了所有地方。我喜欢在零上方放置一个文本,在零值下方放置一个文本。有任何想法吗?

4

1 回答 1

22

你在注释之后:

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) 
于 2012-08-16T19:39:29.740 回答