In one of my scripts I used plot.acf function, but I had to modify it a little to suit my needs. Although my modifications are minor, I believe some people might benefit from it. The problem: currently, in cross-correlation plots main title captions are constructed of 2 names separated by '&' symbol. Such captions occupy too much horizontal space and usually don't fit in plot. A better solution would be to split a caption in two lines (each name on its separate line). I attach a patch which adds an option to do so. Please review it and tell me if such things are worth including into upstream version. I have never contributed code for R project before, so please be patient and tell me if I'm missing some fundamental things (like compatibility with S or whatever). The patch attached does 2 things: 1) Adds new argument main.sep. It allows to customize the titles. Now you can even pass main.sep value containing '\n', so two parts of the caption come on different lines. The default value preserves original behavior. 2) Changes main title captions positioning behavior. Now they are positioned automatically, which ensures nicely looking captions when main.sep containing '\n' is used. If you think the patch might be useful, please let me know and I will submit necessary modifications to the Rd file. Andrey Paramonov -------------- next part -------------- A non-text attachment was scrubbed... Name: plot.acf.patch Type: text/x-diff Size: 1697 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20080525/85557691/attachment.bin>
On Sun, 25 May 2008, ?????? ????????? wrote:> In one of my scripts I used plot.acf function, but I had to modify it > a little to suit my needs. Although my modifications are minor, I > believe some people might benefit from it. > > The problem: currently, in cross-correlation plots main title captions > are constructed of 2 names separated by '&' symbol. Such captions > occupy too much horizontal space and usually don't fit in plot. A > better solution would be to split a caption in two lines (each name on > its separate line).That is the part that needs justification. I've never seen an example where that was the case (and you don't give one), and I use acf() a lot. The examples fit and their series names are not particularly short. Also, the user has the option to supply 'main' to plot.acf via '...', so why is that not sufficient? And you can even suppress the title by main="" and use title() for even more control.> I attach a patch which adds an option to do so. Please review it and > tell me if such things are worth including into upstream version. I > have never contributed code for R project before, so please be patient > and tell me if I'm missing some fundamental things (like compatibility > with S or whatever). > > The patch attached does 2 things: > > 1) Adds new argument main.sep. It allows to customize the titles. Now > you can even pass main.sep value containing '\n', so two parts of the > caption come on different lines. The default value preserves original > behavior. > > 2) Changes main title captions positioning behavior. Now they are > positioned automatically, which ensures nicely looking captions when > main.sep containing '\n' is used. > > If you think the patch might be useful, please let me know and I will > submit necessary modifications to the Rd file. > > Andrey Paramonov >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
2008/5/27 Prof Brian Ripley <ripley at stats.ox.ac.uk>:> That is the part that needs justification. I've never seen an example where > that was the case (and you don't give one), and I use acf() a lot. The > examples fit and their series names are not particularly short. > > Also, the user has the option to supply 'main' to plot.acf via '...', so why > is that not sufficient? And you can even suppress the title by main="" and > use title() for even more control. >Here is an example with real-life series names and plot dimensions: data <- cbind('????? ???????' = arima.sim(n = 100, list(ar = 0.5)), '???. ?????????' = arima.sim(n = 100, list(ar = 0.1))) x11(width = 4.8, height = 4.2) acf(data, mar = c(3, 3, 3, 1) + 0.1, cex.main = 1) I have tried to supply main argument to the acf function: acf(data, mar = c(3, 3, 3, 1) + 0.1, cex.main = 1, main = matrix(c('????? ???????', '????? ??????? &\n???. ?????????', '????? ??????? &\n???. ?????????', '???. ?????????'), 2, 2)) but it doesn't work the desired way. Please see the implementation of plot.acf. title function doesn't seem to play well with par(mfrow = ), so it doesn't help, too. In principle, it's not *that* hard to implement a custom version of multivariate acf plot, but the current version of plot.acf provides some sweet features like y-axes alignment etc. Writing another plot.acf will inevitably lead to massive code duplication, which is bad. I have several ideas of how to tweak current plot.acf so it would suffice my needs: 1) Add new main.sep argument (see the patch). 2) Let plot.acf recognize if main is a matrix and use its elements for different plots, not just coerce it to vector and pass to every title. 3) Let plot.acf recognize if main is a function and call it with 2 arguments (i-series name and j-series name) to compose captions. 1) seems to be the easiest for a user, 2) and 3) provide more freedom. Andrey Paramonov
Seemingly Similar Threads
- Error when posting facebook.feed.publishActionOfUser
- Newbie trying to understand $ so I can understand acf function in stats
- When using ACF, receive error: no applicable method for 'ACF' applied to an object of class "c('double', 'numeric')"
- bug in acf (PR#9360)
- acf function