breaks and labels in ggplot2 0.9.1

4,591 views
Skip to first unread message

nigol

unread,
May 12, 2012, 5:53:10 PM5/12/12
to ggp...@googlegroups.com
I just upgraded to ggplot2 0.9.1, and I am having problems with breaks and labels.
I am experiencing this problem both in R 2.15.0 under windows 7, and R 2.14.2 under cygwin.
Below is a simple reproducible example to illustrate the issue.
I did not experience this kind of problem in previous versions of ggplot2, including version 0.9.

library(ggplot2)
breaks <- c(10, 20, 30, 40)
ggplot(mpg, aes(x=cty, y=hwy)) + geom_point() + scale_y_log10(breaks = breaks, labels = breaks)
>> Error in scale_labels.continuous(scale, major) : 
>>  Breaks and labels are different lengths

It seems that the length of the labels vector has to match the number of breaks shown in the actual plot (not the length of the breaks vector), since the following code works:

library(ggplot2)
breaks <- c(20, 30, 40)
ggplot(mpg, aes(x=cty, y=hwy)) + geom_point() + scale_y_log10(breaks = breaks, labels = breaks)

Is this an intended feature or a new bug?
Is there a general workaround?
Thanks, 
Dario

Kevin Tierney

unread,
May 14, 2012, 4:27:20 PM5/14/12
to ggplot2
I am seeing the same thing in code that worked earlier today prior to
upgrading

scale_y_continuous(breaks = 0:24,
labels=c("MN","1A","2A","3A","4A","5A","6A","7A","8A","9A","10A","11A","12N","1P","2P","3P","4P","5P","6P","7P","8P","9P","10P","11P","MN"))
+

as soon as I comment out this line it works, but I lose the consistent
formatting I need in multiple plots that are generated in a loop

Winston Chang

unread,
May 14, 2012, 5:43:41 PM5/14/12
to Kevin Tierney, ggplot2
I think these problems are related to this issue:

A workaround is to set the limits to include all the breaks, or drop any breaks that are outside the data range.

-Winston

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages