带有单个系列的ggplot上的direct.label错误将被标记 [英] direct.label error on ggplot with single series to be labeled
问题描述
我正在试图解决我在尝试使用 direct.label
标记仅有一个系列的ggplot时遇到的错误。下面举例说明如果只有一个系列, direct.label
失败。
在我的真实数据中,我正在循环区域并希望在子区域上使用直接标签。但是,在我的情况下, 某些 的区域只有一个子区域,导致在使用 direct.label
。任何援助将不胜感激
图书馆(ggplot2)
图书馆(直接标签)
# (df){
nums < - tapply(df $ length,df $ year) ,长度)
data.frame(rating = round(df $ rating [1]),year = as.numeric(names(nums)),number = as.vector(nums))
}) )
#使用直接标签根据等级
p < - ggplot(mry,aes(x = year,y = number,group = rating,color = rating))+ geom_line ()
direct.label(p,last.bumpup)
#仅用于单个评分
mry2 = subset(mry,rating == 10)
p2 < - ggplot(mry2,aes(x = year,y = number,group = rating,color = rating))+ geom_line()
p2
#直接标签在试图用单个系列标注情节时失败
direct.label(p2,last.bumpup)
这确实是一个错误;包维护者已经修复了它。要获取更新的版本,
install.packages(directlabels,repos =http://r-forge.r -project.org)
我刚刚查过,现在一切正常。很好的接收!
I am looking to resolve an error that I encounter when trying to use direct.label
to label a ggplot with only one series. Below is a example to illustrate how direct.label
fails if there is only a single series.
In my real data, I am looping through regions and wanting to use direct labels on the sub-regions. However, in my case some of the regions only have one sub-region resulting in an error when using direct.label
. Any assistance would be greatly appreciated
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")
This indeed was a bug; the package maintainer has already fixed it. To obtain an updated version,
install.packages("directlabels", repos="http://r-forge.r-project.org")
I've just checked, everything now runs fine. Nice catch!
这篇关于带有单个系列的ggplot上的direct.label错误将被标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!