ggplot 中的错误问题:“grid.Call 中的错误(”L_textBounds“, as.graphicsAnnot(x$label), x$x, x$y, … ”
我试图在 ggplot 中制作一个条形图,其中我通过强制其中一些标签为长度为零的字符串(即“”)来指定要显示的标签。 收到错误
Error in grid.Call("L_textBounds", as.graphicsAnnot(x$label), x$x, x$y,
: Polygon edge not found (zero-width or zero-height?)
但是,我在尝试这样做时
。下面的代码将重现该错误。
希望有人能解释为什么我不能这样做。
library(ggplot2)
dataset<-matrix(ncol=3,nrow=12)
colnames(dataset)<-c("Score","Action","Bin")
dataset[1:9,1]<-c(1,2,3,-2,7,10,12,3,4)
dataset[1:9,2]<-rep(1,9)
dataset[10:12,1]<-c(-1,-2,-3)
dataset[10:12,2]<-rep(2,3)
dataset[1:12,3]<-as.character(cut(dataset[1:12,1:1],breaks=4))
myDataset<-as.data.frame(dataset)
chosenbreaks<-as.vector(unique(dataset[1:12,3]))
chosenlabels<-as.vector(c(chosenbreaks[1],"","",chosenbreaks[4]))
fullplot<-ggplot(myDataset, aes(Bin, fill=Action))
+ geom_bar(position="stack")
+ opts(axis.text.x = theme_text(angle = 45,size=8))
+ scale_x_discrete("test",breaks=chosenbreaks,labels=chosenlabels)
fullplot
预先感谢,
克里斯蒂安
I am trying to make a barplot in ggplot in which I specify which labels to show by enforcing some of them to be strings of length zero, that is as "". However, I get the error
Error in grid.Call("L_textBounds", as.graphicsAnnot(x$label), x$x, x$y,
: Polygon edge not found (zero-width or zero-height?)
when trying to do so.
The below code will reproduce the error.
Hope somebody has an explanation to why I cannot do as I do.
library(ggplot2)
dataset<-matrix(ncol=3,nrow=12)
colnames(dataset)<-c("Score","Action","Bin")
dataset[1:9,1]<-c(1,2,3,-2,7,10,12,3,4)
dataset[1:9,2]<-rep(1,9)
dataset[10:12,1]<-c(-1,-2,-3)
dataset[10:12,2]<-rep(2,3)
dataset[1:12,3]<-as.character(cut(dataset[1:12,1:1],breaks=4))
myDataset<-as.data.frame(dataset)
chosenbreaks<-as.vector(unique(dataset[1:12,3]))
chosenlabels<-as.vector(c(chosenbreaks[1],"","",chosenbreaks[4]))
fullplot<-ggplot(myDataset, aes(Bin, fill=Action))
+ geom_bar(position="stack")
+ opts(axis.text.x = theme_text(angle = 45,size=8))
+ scale_x_discrete("test",breaks=chosenbreaks,labels=chosenlabels)
fullplot
Thanks in advance,
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我更新了我的软件包,重新启动了我的机器,突然它就工作了。我不知道为什么,但我很高兴它有效。非常感谢所有贡献者 - SO 太棒了!
I updated my packages, restarted my machine and suddenly it worked. I do not know why, but I am happy that it know works. Thanks a lot to all the contributors - SO is just great!
我在 Mac 上也遇到了同样的问题。我必须使用 Font Book 应用删除一些重复的字体。事实是,这些字体的重复项已经被禁用(大约一年前它们在 NeoOffice 中引起了问题)。我不知道为什么这有效。 (请注意,我删除了我认为是这些字体的旧版本的内容——Arial、Times 和 Palatino 就是其中的一些。)也许这对这个主题有一些启发,但我不知道如何。
I had this same problem, on a Mac. I had to delete some duplicate fonts I had, using the app Font Book. Thing is, the duplicates of these fonts had already been disabled (they had caused a problem in NeoOffice a year or so ago). I don't know why this worked. (Note I deleted what I think were the older versions of these fonts -- Arial, Times, and Palatino were a few of them.) Perhaps this sheds some light on the subject, but I don't know how.