我使用ggplot2和geom_line()
图中的直接标签包,我希望其中一个标签可以读取“X-M”。但是,在我的data.frame()
“X-M”列名称被重命名为“X.M”,并且我无法找到有关如何使用自定义标签名称提供direct.label
函数的文档,也没有阅读源代码的帮助信息。 (directabels似乎并没有兑现在ggplot规模,这是我想的第一件事就是设定的标签名称。)如何使用ggplot2 +直接标签的标签的自定义名称
示例代码:
library("scales")
library("reshape2")
library("ggplot2")
library("directlabels")
data = data.frame(
C = c(1.2, 1.4, 0.3, -2.0, 0.5),
I = c(1.2, 1.5, -1.3, -3.8, 1.8),
G = c(0.2, 0.3, 0.3, 0.2, 0.2),
"X-M" = c(2.9, -0.7, 0.3, -2.8, 1.5) +
c(-2.7, 0.2, 0.4, 3.6, -2.4),
year = c("2006", "2007", "2008", "2009", "2010"))
p <- ggplot(data = melt(data), aes(year, value, color = variable)) +
geom_line(aes(group = variable)) +
scale_color_hue(breaks = c("C", "I", "G", "X.M"),
labels = c("C", "I", "G", "X-M")) # directlabels doesn't
# use this
# Compare:
p
# with:
direct.label(p, list(last.points, hjust = -0.25))
产生的图形可以看出here。带有直接标签的人使用“X.M”而不是“X-M”。提前谢谢了!
+1的可重复的例子。欢迎来到SO。 – Andrie 2012-07-17 23:07:54