error with function date_breaks and date_format

5,811 views
Skip to first unread message

SNV Krishna

unread,
Mar 13, 2012, 6:08:28 AM3/13/12
to ggp...@googlegroups.com

Hi All,

 

There seems to be a problem with date_breaks, I ran the example code and following error is displayed. Could you please help me.

 

# dataset ‘economics’ from ggplot2 ver 0.9.0

> qp = qplot(date, psavert/100, data = economics, geom = "line") + labs(x = "Year", y = "Personal savings rate")

 

> qp + scale_x_date(breaks = date_breaks("5 years"),labels = date_format("%Y"))

Error in scale_date(c("x", "xmin", "xmax", "xend"), expand = expand, breaks = breaks,  :

  could not find function "date_breaks"

 

even similar error is displayed for “date_format” function.

 

> sessionInfo()

R version 2.14.2 (2012-02-29)

Platform: i386-pc-mingw32/i386 (32-bit)

 

locale:

[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252  

[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                         

[5] LC_TIME=English_United States.1252   

 

attached base packages:

[1] stats     graphics  grDevices utils     datasets  methods   base    

 

other attached packages:

[1] ggplot2_0.9.0

 

loaded via a namespace (and not attached):

[1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.1       grid_2.14.2      

 [5] MASS_7.3-17        memoise_0.1        munsell_0.3        plyr_1.7.1       

 [9] proto_0.3-9.2      RColorBrewer_1.0-5 reshape2_1.2.1     scales_0.2.0     

[13] stringr_0.6        tools_2.14.2     

 

Thanks for the help,

 

Regards,

 

S.N.V. Krishna

 

Joshua Wiley

unread,
Mar 13, 2012, 6:19:50 AM3/13/12
to SNV Krishna, ggp...@googlegroups.com
Hi,

It is in the scales package, so:

require(ggplot2)
require(scales)


qplot(date, psavert/100, data = economics, geom = "line") +

labs(x = "Year", y = "Personal savings rate") +


scale_x_date(breaks = date_breaks("5 years"),labels = date_format("%Y"))

should do the trick.

Cheers,

Josh

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

SNV Krishna

unread,
Mar 13, 2012, 6:18:41 AM3/13/12
to Joshua Wiley, ggp...@googlegroups.com
Hi, Many thanks it worked, Regards,

S.N.V. Krishna

Dennis Murphy

unread,
Mar 13, 2012, 7:41:37 AM3/13/12
to SNV Krishna, ggp...@googlegroups.com
Just to add a note to Josh's solution:

One of the differences in ggplot2-0.9.0 relative to 0.8.9 and earlier
is that other packages are no longer autoloaded with ggplot2; for
example, plyr and reshape are no longer 'co-loaded'. Moreover,
formatting and labeling functions that used to be in ggplot2-0.8.9
have been moved into the scales package along with a large number of
transformation functions, so if you intend to modify your positional
guides (axes) through transformation or axis label formatting, or
modify strip labels with a labeling function, you should load the
scales package along with ggplot2. It is probably not a bad idea to
write a custom .Rprofile function that loads a set of packages at
startup if you use them routinely in your work.

Dennis

Joshua Wiley

unread,
Mar 13, 2012, 9:59:04 AM3/13/12
to SNV Krishna, ggp...@googlegroups.com, Dennis Murphy
On Tue, Mar 13, 2012 at 4:41 AM, Dennis Murphy <djm...@gmail.com> wrote:
> Just to add a note to Josh's solution:
>
> One of the differences in ggplot2-0.9.0 relative to 0.8.9 and earlier
> is that other packages are no longer autoloaded with ggplot2; for
> example, plyr and reshape are no longer 'co-loaded'. Moreover,
> formatting and labeling functions that used to be in ggplot2-0.8.9
> have been moved into the scales package along with a large number of
> transformation functions, so if you intend to modify your positional
> guides (axes) through transformation or axis label formatting, or
> modify strip labels with a labeling function, you should load the
> scales package along with ggplot2. It is probably not a bad idea to
> write a custom .Rprofile function that loads a set of packages at
> startup if you use them routinely in your work.

Good point. Also, you may find the transition guide to 0.9
(spearheaded by Dennis) useful:
http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf

many examples you find online (or in Hadley Wickham's ggplot2 book)
may not work exactly the same in 0.9. The guide is helpful for
understanding how to adapt to the new, better world (better world of
software implementations of the grammar of graphics, that is).

Reply all
Reply to author
Forward
0 new messages