MyNixOS website logo
Description

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.

ContourFunctions

Travis-CI BuildStatus CRAN_Status_Badge Codecov testcoverage

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

Overview

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.

Installation

# It can be installed like any other package
install.packages("ContourFunctions")

# Or the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("CollinErickson/contour")

Usage

Plot a grid of data:

library(ContourFunctions)
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:

set.seed(0)
x <- runif(20)
y <- runif(20)
z <- exp(-(x-.5)^2-5*(y-.5)^2)
cf_data(x,y,z)

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])})

Metadata

Version

0.1.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows