An open API service indexing awesome lists of open source software.

https://github.com/blmoore/mandelbrot

Mandelbrot set R package
https://github.com/blmoore/mandelbrot

fractal mandelbrot r rstats

Last synced: 11 months ago
JSON representation

Mandelbrot set R package

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "figs/README-"
)
```

```{r icon, echo=FALSE, fig.align='right', fig.width=2, fig.height=1.5, fig.path="figs/", fig.show='hide'}
# draw small readme icon
library(mandelbrot)
mb <- mandelbrot(xlim = c(-3, 1), c(-1.8, 1.8))
old_par <- par()
par(bg = NA, mar=rep(0, 4))
image(mb, col = c(rgb(0, 0, 0, 0), "grey80"), axes = F)
par <- old_par
```

# mandelbrot

[![travis_status](https://travis-ci.org/blmoore/mandelbrot.svg?branch=master)](https://travis-ci.org/blmoore/mandelbrot)
[![codecov](https://codecov.io/gh/blmoore/mandelbrot/branch/master/graph/badge.svg)](https://codecov.io/gh/blmoore/mandelbrot)
[![CRAN_badge](http://www.r-pkg.org/badges/version/mandelbrot)](https://cran.r-project.org/package=mandelbrot)

Curious whether your favourite complex number is a member
of the Mandelbrot set?

—No? Then probably you just want to draw pretty pictures.

## Install

Install from CRAN:

```{r cran_install, eval=FALSE}
install.packages("mandelbrot")
```

Or get the development version:

```{r github_install, eval=FALSE}
devtools::install_github("blmoore/mandelbrot")
```

## Examples

```{r b_n_w}
library(mandelbrot)

mb <- mandelbrot()
plot(mb)
```

Pretty colours:
```{r trip}
mb <- mandelbrot(xlim = c(-0.8438146, -0.8226294),
ylim = c(0.1963144, 0.2174996),
iterations = 500, resolution = 800)

cols <- mandelbrot_palette(RColorBrewer::brewer.pal(11, "Spectral"), fold = FALSE)
plot(mb, col = cols)
```

Experiment with transforms:

```{r trans, fig.height=3.5, fig.width=7}
par(mfrow = c(1, 2), pty = "s", mar = rep(0, 4))
plot(mb, col = cols, transform = "inverse")
plot(mb, col = cols, transform = "log")
```

```{r reset_par, echo=FALSE}
par <- old_par
```

Don't like `image`? Convert to a `data.frame` and use with ggplot2:

```{r ggplot}
library(ggplot2)

mb <- mandelbrot(xlim = c(-0.8335, -0.8325),
ylim = c(0.205, 0.206),
resolution = 1200L,
iterations = 1000)

# weird uneven palette made for a heatmap viz:
# https://benjaminlmoore.wordpress.com/2015/04/09/recreating-the-vaccination-heatmaps-in-r/
cols <- c(
colorRampPalette(c("#e7f0fa", "#c9e2f6", "#95cbee",
"#0099dc", "#4ab04a", "#ffd73e"))(10),
colorRampPalette(c("#eec73a", "#e29421", "#e29421",
"#f05336","#ce472e"), bias=2)(90),
"black")

df <- as.data.frame(mb)
ggplot(df, aes(x = x, y = y, fill = value)) +
geom_raster(interpolate = TRUE) + theme_void() +
scale_fill_gradientn(colours = cols, guide = "none")

```

`mandelbrot0` is a faster interface for `as.data.frame(mandelbrot(...))`.

## See also

* [shinybrot](https://github.com/blmoore/shinybrot) is a Shiny web app
that enables interactive exploration of the Mandelbrot set as generated
by this package. Hosted on shinyapps: https://blmr.shinyapps.io/shinybrot
* [This blog post](https://benjaminlmoore.wordpress.com/2017/06/27/the-mandelbrot-set-in-r/)
on the R package and Shiny app.

## Credits

* Wraps original R / C code by [mariodosreis](https://github.com/mariodosreis) (see R package [fractal](https://github.com/mariodosreis/fractal)).