A convenient wrapper function for plotting one or more functions on a single plot. If the function(s) is/are expensive to calculate, function values can be calculated in parallel.

1 2 3 |

`fun` |
A function or a list of functions to be plotted. These functions should take a single, numeric vector argument and return a corresponding vector of outputs. |

`xlim` |
A numeric vector with two elements that define the domain over which the function(s) will be evaluated
and plotted, just as in |

`col` |
A vector of colors to use in the plotting. It's length should match the length of |

`lty` |
A vector of line types to use in the plotting. It's length should match the length of |

`type` |
A single character indicating the type of plotting. This is passed to the |

`legendLabels` |
A character vector with descriptive names that will appear in the legend, corresponding to each function
If |

`relX` |
A numeric value in [0, 1] designating the relative horizontal (x) position of the legend in the plot. |

`relY` |
A numeric value in [0, 1] designating the relative vertical (y) position of the legend in the plot. |

`nPoints` |
The number of points that are evaluated and plotted for each function over the interval given by |

`njobs` |
The number of parallel jobs to spawn using |

`...` |
Additional graphical arguments passed to |

The plot of the function(s)

Landon Sego

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ```
# A single function with a single argument
f <- function(x) x^2
plotFun(f, c(-2, 3), col = "Black", lty = 2, las = 1)
# A handful of beta density functions, note how they take a single argument
fList <- list(function(x) dbeta(x, 10, 10),
function(y) dbeta(y, 3, 3),
function(z) dbeta(z, 0.5, 0.50))
# Plot them all on the same plot
plotFun(fList, c(0.0001, 0.9999), ylim = c(0, 3.5),
col = c("Red", "Black", "Blue"), lty = rep(1, 3),
xlab = "x", ylab = expression(f(x)),
legendLabels = c("a = 10, b = 10", "a = 3, b = 3", "a = 0.5, b = 0.5"),
relX = 0.6, relY = 1, lwd = 3, main = "Gamma Densities")
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.