Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with error in ggplot: “Error in grid.Call(”L_textBounds“, as.graphicsAnnot(x$label), x$x, x$y, … ” [duplicate]

Tags:

r

ggplot2

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

like image 598
Christian Bøhlke Avatar asked Mar 25 '11 13:03

Christian Bøhlke


2 Answers

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.

like image 143
Nat Poor Avatar answered Nov 16 '22 15:11

Nat Poor


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!

like image 11
Christian Bøhlke Avatar answered Nov 16 '22 16:11

Christian Bøhlke