Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>the way to set up a default is like this:</p> <pre><code>testFunction &lt;- function( requiredParam, optionalParam=TRUE, alsoOptional=123 ) { print(requiredParam) if (optionalParam==TRUE) print("you kept the default for optionalParam") paste("for alsoOptional you entered", alsoOptional) } </code></pre> <p>*<strong><em>EDIT</em>*</strong></p> <p>Oh, ok... so I think I have a better idea of what you are asking. It looks like you're not sure how to bring the optional facet into the ggplot object. How about this:</p> <pre><code> qhist &lt;- function(variable, df, heading, facets=NULL) { d &lt;- qplot(variable, data = df, geom = "histogram", binwidth = 2000, xlab = "Salary", ylab = "Noms") + theme_bw() + scale_x_continuous(limits=c(40000,250000), breaks=c(50000,100000,150000,200000,250000), labels=c("50k","100k","150k","200k","250k")) + opts(title = heading, plot.title = theme_text(face = "bold", size = 14), strip.text.x = theme_text(size = 10, face = 'bold')) # If facets argument supplied add the following, else do not add this code if (is.null(facets)==FALSE) d &lt;- d + facet_wrap(as.formula(paste("~", facets))) d return(d) } </code></pre> <p>I have not tested this code at all. But the general idea is that the facet_wrap expects a formula, so if the facets are passed as a character string you can build a formula with <code>as.formula()</code> and then add it to the plot object. </p> <p>If I were doing it, I would have the function accept an optional facet formula and then pass that facet formula directly into the <code>facet_wrap</code>. That would negate the need for the <code>as.formula()</code> call to convert the text into a formula. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload