13

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

Christian Bøhlke
  • 779
  • 1
  • 7
  • 18
  • @Christian - I am not able to reproduce the error you describe. I did get a `invalid arugment to unary operator` because your statements to not end in the `+` operator so R doesn't know to add the additional lines to `fullplot`. Once I fixed that, the plot works fine on my machine. – Chase Mar 25 '11 at 14:19
  • Much better effort, Christian. This code executes without a problem on my machine. Can you please paste the results of sessionInfo() in your question? You may have an old version of ggplot2 – Andrie Mar 25 '11 at 14:31
  • @Christian, this works fine on my machine too. The result of sessionInfo() will be helpful. – Sam Mar 25 '11 at 14:37
  • Here it is @Chase, @Andrie, @Sam: sessionInfo() R version 2.12.2 (2011-02-25) Platform: i386-pc- mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] ggplot2_0.8.9 proto_0.3-9.1 reshape_0.8.4 plyr_1.4 loaded via a namespace (and not attached): [1] tools_2.12.2 – Christian Bøhlke Mar 25 '11 at 15:07
  • There is a [similar report](http://groups.google.com/group/ggplot2/browse_thread/thread/60fed22af2311862/93e2fb975af62f18?lnk=raot&pli=1) (although on a mac rather than windows) on the [ggplot2 mailing list](http://groups.google.com/group/ggplot2). The solution involved cleaning out the font cache I believe. – Ista Mar 25 '11 at 15:33
  • @Ista Saw that post before I posted here, however, it offers no concrete solution. It works in the case described [in](http://groups.google.com/group/ggplot2/browse_thread/thread/60fed22af2311862/93e2fb975af62f18?lnk=raot&pli=1), but as is also pointed out there; the smoking gun is not resolved. I tried switching to another machine with R 2.12.1, but that just give me the same error. – Christian Bøhlke Mar 25 '11 at 16:00
  • @Christian A google search for this error seems to indicate that there also are associated warning messages, particularly with missing fonts. Did you get any warning messages? If so, can you post these as well? – Andrie Mar 25 '11 at 16:10
  • @Andrie I get no warnings, so nothing to work with there :-( I am trying to update the packages in use, but that has not helped so far. – Christian Bøhlke Mar 25 '11 at 16:45
  • From [Paul Murrell](http://tolstoy.newcastle.edu.au/R/e6/help/09/04/11828.html) on the R help mailing list: _The error message says it all: a calculation is being performed to find the edge of a polygon (from a grobX() or grobY() call?), but the polygon has zero width or zero height so the calculation is floundering._ It is weird that some of you are actually getting the plot, as the post by Murrell suggest a concrete error. – Christian Bøhlke Mar 25 '11 at 16:57
  • I doubt updating your packages will help. Other than your locale, your systemInfo() is the same as mine. My guess as to the problem: a missing font or something similar. A rectangle (polygon) round an empty font will have zero width. – Andrie Mar 25 '11 at 17:21
  • Apparently this is a duplicate of an OSX-specific report/solution. Someone can help me out - does the OP say he's using Mac? (The `i386-pc- mingw32/i386` stuff is alien to me.) I get this error with Windows 7 with a different workflow, so is this another example of zealous editor voting making life more complicated for everyone? – geotheory Dec 10 '13 at 16:36

2 Answers2

12

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!

Christian Bøhlke
  • 779
  • 1
  • 7
  • 18
  • 1
    Encountered the same issue when I had been running ggplots with specific fonts and installing Microsoft Office simultaneously. A reboot did the trick for me, too. I was on OSX 10.8.4 w/ R 3.0 – metasequoia Jun 07 '13 at 05:34
  • same with me, i had just installed MS office, reboot fixed – Dan Jun 25 '13 at 15:27
6

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.

Nat Poor
  • 61
  • 1
  • 1