2

Sounds probably more complicated than what I want to achieve :) Since I do a lot of formatting to my plots I want to wrap this all in a function. However some formatting and setting of parameters is done before the plotn call and adding the legend and icon as well as formatting them is done after the plot call. So I basically want a function like:

myFormattedPlots<-function(plotFunctionName, plotFunctionParameters...)

The parameters list depends of course on the function..but I image something like this:

myFormattedPlots<-function("plot.xts",MyXTSTimeSeries){
   par(xpd=FALSE)
...
plot.xts(MyXTSTimeSeries)
grid.raster(logo,x=c(0.05),y=c(0.02),width=0.05,height=0.03)
}

How can I achieve that?

4
  • 1
    Why don't you pass directly the plot function to your function myFormattedPlots instead of its name? It's so easy in R Commented May 28, 2014 at 7:26
  • can you show me an example? Never did that before... Commented May 28, 2014 at 7:27
  • 2
    I suggest you also study ... and do.call as those could be quite useful for your purpose. Commented May 28, 2014 at 7:29
  • See my answer for an example Commented May 28, 2014 at 7:30

1 Answer 1

4

You can give the function instead of its name in R. It would be that easy on your example:

myFormattedPlots<-function(func,MyXTSTimeSeries){
   par(xpd=FALSE)
   func(MyXTSTimeSeries)
   grid.raster(logo,x=c(0.05),y=c(0.02),width=0.05,height=0.03)
}
myFormattedPlots(plot.xts, your.time.series)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.