knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.height="400px"
)
knitr::opts_knit$set(global.par = TRUE)
par(mar = rep(0, 4), mai = rep(0, 4))

attractor

The goal of attractor is to generate and plot strange attractors.

Using this package is fast, because:

  1. The attractor algorithm uses Rcpp for speed.
  2. The resulting attractor is discretized (binned) into a much smaller matrix, making plotting very fast.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("andrie/attractor")

Example

Create a strange attractor with 10 million points, then discretize to a matrix with dimensions 400 x 400:

library(magrittr)
library(attractor)

a <- seed_sprott_7e(21031)

dat <- 
  a %>% 
  attractor_sprott_7e(1e6, dims = c(400, 400))
str(dat)

Plotting a strange attractor

par(mar = rep(0, 4), mai = rep(0, 4))
dat %>% 
  recolour() %>% 
  plot()

Recolour the plot

Use recolour() to change the colours. You can use any of the colours defined by the scales::col_numeric() function. From the help of ?scales::col_numeric():

The palette argument can be any of the following:

  1. A character vector of RGB or named colours. Examples: palette(), c("#000000", "#0000FF", "#FFFFFF"), topo.colors(10)

  2. The name of an RColorBrewer palette, e.g. "BuPu" or "Greens".

  3. A function that receives a single value between 0 and 1 and returns a colour. Examples: colorRamp(c("#000000", "#FFFFFF"), interpolate="spline").

Use the Oranges palette:

dat %>% 
  recolour("Oranges") %>%
  plot()

To change the background colour, specify a zero_colour:

dat %>% 
  recolour("Oranges", zero_colour = "#FFFAF6") %>%
  plot()

You can also invert the palette

dat %>% 
  recolour("Oranges", zero_colour = "grey20", invert = TRUE) %>%
  plot()

Try the Spectral palette:

dat %>% 
  recolour("Spectral", zero_colour = "#9E0142") %>%
  plot()

With inversion:

dat %>% 
  recolour("Spectral", invert = TRUE, zero_colour = "#5E4FA2") %>%
  plot()


andrie/attractor documentation built on May 13, 2019, 11:56 p.m.