我使用直接标签来标注我的情节。正如你在这幅图中看到的那样,标签在geom_line之后,但是我想在geom_smooth之后找到它们。这是由直接标签支持吗?或者其他任何想法如何实现这一目标?提前致谢!如何在geom_smooth之后显示directlabels而不是在geom_line之后显示?
图片情节:http://i.stack.imgur.com/2vZmk.png
这是我的代码:
library("ggplot2")
set.seed(124234345)
# Generate data
df.2 <- data.frame("n_gram" = c("word1"),
"year" = rep(100:199),
"match_count" = runif(100 ,min = 1000 , max = 2000))
df.2 <- rbind(df.2, data.frame("n_gram" = c("word2"),
"year" = rep(100:199),
"match_count" = runif(100 ,min = 1000 , max = 2000)))
# plot
ggplot(df.2, aes(year, match_count, group=n_gram, color=n_gram)) +
geom_line(alpha = I(7/10), color="grey", show_guide=F) +
stat_smooth(size=2, span=0.3, se=F, show_guide=F) +
geom_dl(aes(label=n_gram), method = "last.bumpup", show_guide=F) +
xlim(c(100,220))
谢谢!如果我在具有更多组的数据集上使用它,手动调整每个标签有点繁琐。但我用你的想法来创建一个功能来自动完成此操作。我会发布这个作为我自己问题的答案,我希望这是适当的礼仪。 – 2012-04-09 06:41:44
是的,请做。这个论坛的重点(至少对我来说)是以可搜索的格式获得问题的最佳解决方案。有时我们会根据别人的反应而改进它们。 – 2012-04-09 13:55:35