本文介绍了ggplot中出现错误:“grid.Call中出现错误(”L_textBounds“,as.graphicsAnnot(x $ label),x $ x,x $ y,...”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ggplot中创建一个barplot,其中我通过强制其中一些长度为零的字符串来指定显示哪些标签,即。然而,我得到了错误

  grid.Call错误(L_textBounds,as.graphicsAnnot(x $ label),x $ x,x $ y,
:找不到多边形边界(零宽或零高?)

试图这样做。



下面的代码会重现错误。



有人解释为什么我不能这样做。

  library(ggplot2)

数据集< ; -matrix(ncol = 3,nrow = 12)
colnames(数据集)< -c(Score,Action,Bin)
dataset [1:9,1]< ; -c(1,2,3,-2,7,10,12,3,4)
数据集[1:9,2]< -rep(1,9)
数据集[ 10:12,1]< -c(-1,-2,-3)
数据集[10:12,2]< -rep(2,3)
数据集[1:12 ,3]< -as.character(cut(dataset [1:12,1:1],bre​​aks = 4))
myDataset< -as.data.frame(dataset)
$ b $ (selectedbreaks [1],,,selectedbreaks [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 = selectedbreaks,labels =

fullplot

预先感谢,



Christian

解决方案

我更新了包,重新启动了我的机器,我不知道为什么,但我很高兴知道它的作品。非常感谢所有贡献者 - 这真是太棒了!

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

解决方案

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!

这篇关于ggplot中出现错误:“grid.Call中出现错误(”L_textBounds“,as.graphicsAnnot(x $ label),x $ x,x $ y,...”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 11:57