ContourFunctions v0.1.1


Monthly downloads



Create Contour Plots from Data or a Function

Provides functions for making contour plots. The contour plot can be created from grid data, a function, or a data set. If non-grid data is given, then a Gaussian process is fit to the data and used to create the contour plot.



Travis-CI Build
Status CRAN\_Status\_Badge Codecov test

This is an R package that provides simple functions for creating contour plots.


The main functions are:

  • cf_grid: Makes a contour plot from grid data.

  • cf_func: Makes a contour plot for a function.

  • cf_data: Makes a contour plot for a data set by fitting a Gaussian process model.

  • cf: Passes arguments to cf_function or cf_data depending on whether the first argument is a function or numeric.

All of these functions make the plot using base graphics by default. To make plots using ggplot2, add the argument gg=TRUE, or put g in front of the function name. E.g., gcf_data(...) is the same as cf_data(..., gg=TRUE), and makes a similar plot to cf_data but using ggplot2.

There are two functions for making plots in higher dimensions:

  • cf_4dim: Plots functions with four inputs by making a series of contour plots.

  • cf_highdim: Plots for higher dimensional inputs by making a contour plot for each pair of input dimensions and holding the other inputs constant or averaging over them.


# It can be installed like any other package

# Or the the development version from GitHub:
# install.packages("devtools")


Plot a grid of data:

a <- b <- seq(-4*pi, 4*pi, len = 27)
r <- sqrt(outer(a^2, b^2, "+"))
cf_grid(a, b, cos(r^2)*exp(-r/(2*pi)))

Plot a function with two input dimensions:

f1 <- function(r) cos(r[1]^2 + r[2]^2)*exp(-sqrt(r[1]^2 + r[2]^2)/(2*pi))
cf_func(f1, xlim = c(-4*pi, 4*pi), ylim = c(-4*pi, 4*pi))

Using data with two inputs and an output, fit a Gaussian process model and show the contour surface with dots where the points are:

x <- runif(20)
y <- runif(20)
z <- exp(-(x-.5)^2-5*(y-.5)^2)

For more than two input dimensions:

friedman <- function(x) {
  10*sin(pi*x[1]*x[2]) + 20*(x[3]-.5)^2 + 10*x[4] + 5*x[5]
cf_highdim(friedman, 5, color.palette=topo.colors)

For (three or) four inputs dimensions:

cf_4dim(function(x) {x[1] + x[2]^2 + sin(2*pi*x[3])})

Functions in ContourFunctions

Name Description
cf_func Makes filled contour plot from function
gcf_grid Create contour plot from grid data using ggplot2
gcf_data Contour plot from data
gcf_func Makes filled contour plot from function
multicolor.title Makes plot title using specified colors for the text
text_plot Make a plot with only text
eval_over_grid_with_batch Evaluate function over grid of points
cf_highdim Plot 2D contour slices of higher dimensional functions
csa Close all open screens
cm.colors.strong Strong version of cm.colors color palette
cf_grid Create a contour plot from a grid of data
cf_4dim Plot 2D contour slices of four dimensional functions
cf_data Contour plot from data
cf Make contour plot from data or function
gcf Make contour plot from data or function using ggplot2
No Results!

Vignettes of ContourFunctions

No Results!

Last month downloads


Type Package
License GPL-3
RoxygenNote 6.1.1
VignetteBuilder knitr
Encoding UTF-8
NeedsCompilation no
Packaged 2019-05-20 02:47:59 UTC; cbe117
Repository CRAN
Date/Publication 2019-05-20 04:10:03 UTC

Include our badge in your README