我期待解决,我尝试使用时遇到错误direct.label
来标记ggplot只有一个系列。 下面是说明如何一个例子direct.label
如果只有一个单一的系列失败。
在我的真实的数据,我通过区域循环并希望在分区域使用直接标签。 然而,在我的情况下, 一些地区的只有从而导致错误当使用一个子区域direct.label
。 任何援助将不胜感激
library(ggplot2)
library(directlabels)
# sample data from ggplot2 movies data
mry <- do.call(rbind, by(movies, round(movies$rating), function(df) {
nums <- tapply(df$length, df$year, length)
data.frame(rating=round(df$rating[1]), year = as.numeric(names(nums)), number=as.vector(nums))
}))
# use direct labels to label based on rating
p <- ggplot(mry, aes(x=year, y=number, group=rating, color=rating)) + geom_line()
direct.label(p, "last.bumpup")
# subset to only a single rating
mry2 = subset(mry, rating==10)
p2 <- ggplot(mry2, aes(x=year, y=number, group=rating, color=rating)) + geom_line()
p2
# direct labels fails when attempting to label plot with a single series
direct.label(p2, "last.bumpup")