与单系列ggplot direct.label错误标记(direct.label error on

2019-10-19 23:59发布

我期待解决,我尝试使用时遇到错误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")

Answer 1:

这的确是一个错误; 该软件包的维护者已经固定它。 为了获得一个更新的版本,

install.packages("directlabels", repos="http://r-forge.r-project.org")

我刚刚检查,现在一切都运行良好。 尼斯赶上!



文章来源: direct.label error on ggplot with single series to be labeled
标签: r ggplot2