https://github.com/andrie/attractor
Generate and plot a strange attractor using R
https://github.com/andrie/attractor
r r-package rstats
Last synced: about 1 month ago
JSON representation
Generate and plot a strange attractor using R
- Host: GitHub
- URL: https://github.com/andrie/attractor
- Owner: andrie
- License: other
- Created: 2019-04-27T10:43:43.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-13T14:26:57.000Z (about 6 years ago)
- Last Synced: 2025-02-14T13:17:01.654Z (3 months ago)
- Topics: r, r-package, rstats
- Language: C++
- Homepage: https://andrie.github.io/attractor
- Size: 21.1 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
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.
1. The resulting attractor is discretized (binned) into a much smaller matrix, making plotting very fast.## Installation
You can install the development version from [GitHub](https://github.com/) with:
``` r
# 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`:
```{r}
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
```{r}
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:
```{r}
dat %>%
recolour("Oranges") %>%
plot()
```To change the background colour, specify a `zero_colour`:
```{r}
dat %>%
recolour("Oranges", zero_colour = "#FFFAF6") %>%
plot()
```You can also invert the palette
```{r}
dat %>%
recolour("Oranges", zero_colour = "grey20", invert = TRUE) %>%
plot()
```Try the `Spectral` palette:
```{r}
dat %>%
recolour("Spectral", zero_colour = "#9E0142") %>%
plot()
```With inversion:
```{r}
dat %>%
recolour("Spectral", invert = TRUE, zero_colour = "#5E4FA2") %>%
plot()
```