10 PRINT mazes with ggplot2

[This article was first published on Higher Order Functions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

There is a celebrated Commodore 64 program that randomly prints outs / and \
characters and fills the screen with neat-looking maze designs. It is just one
line of code, but there is a whole book written about
it.

10 PRINT CHR$(205.5+RND(1)); : GOTO 10
Screenshots of 10 PRINT in action
Screenshots of the 10 PRINT program in action. Images taken from the 10 PRINT book.

The basic idea, from my reading of the code, is that CHR$(205) is \,
CHR$(206) is /, and the program randomly selects between the two by adding a
random number to 205.5. Endlessly looping over this command fills the screen
with that pleasing maze pattern.

In R, we could replicate this functionality with by randomly sampling the
slashes:

<span class="n">sample_n_slashes</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="n">sample</span><span class="p">(</span><span class="nf">c</span><span class="p">(</span><span class="s2">"/"</span><span class="p">,</span><span class="w"> </span><span class="s2">"\\"</span><span class="p">),</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="n">replace</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">withr</span><span class="o">::</span><span class="n">with_options</span><span class="p">(</span><span class="w">
  </span><span class="nf">list</span><span class="p">(</span><span class="n">width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">),</span><span class="w"> 
  </span><span class="n">cat</span><span class="p">(</span><span class="n">sample_n_slashes</span><span class="p">(</span><span class="m">800</span><span class="p">),</span><span class="w"> </span><span class="n">sep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">""</span><span class="p">,</span><span class="w"> </span><span class="n">fill</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span><span class="w">
</span><span class="p">)</span><span class="w">
</span><span class="c1">#> //////\/\\/\/\/\/\\//\\\\//\//\/\//\///\</span><span class="w">
</span><span class="c1">#> \\\/\//\\/\/////////////\\/\//\\\/\//\\\</span><span class="w">
</span><span class="c1">#> /\\/\/\//\/\/\\/\\/\/\//\\\\//\/\\\/\///</span><span class="w">
</span><span class="c1">#> \\//\/\\\/\///\\/\/\/////\//\///\/\/\//\</span><span class="w">
</span><span class="c1">#> /\/\//\///\//\//\//\/\//\\/\\\\\/\\\//\/</span><span class="w">
</span><span class="c1">#> //\\\\\//////\//\//\/\//\\////\/\\\/\/\/</span><span class="w">
</span><span class="c1">#> \\////\/\\/\////\//////\\/\\/////\/////\</span><span class="w">
</span><span class="c1">#> /\/\/\/\/\\///\/\\\\/\/\\//\/\\/\\\\\\//</span><span class="w">
</span><span class="c1">#> //\\\/\///\///\/\\\//\//\\\\//\\/\\/\/\/</span><span class="w">
</span><span class="c1">#> /\\/\//\\//\/\\\\\/\\\/\\\/\/\/\/\////\/</span><span class="w">
</span><span class="c1">#> /\//\\//\////\\\///\//\/\\\/\\///\//\\\\</span><span class="w">
</span><span class="c1">#> /\//\\////\/\\\//\\\//\/\///\\\\\/\/\\//</span><span class="w">
</span><span class="c1">#> \\////\\/\\\\\\///\///\//\\\/\\\\//\////</span><span class="w">
</span><span class="c1">#> \\\///\/\//\//\/\//\/\/\\\/\/\\///\/////</span><span class="w">
</span><span class="c1">#> \\/\\//\\\\\\///\\\\/\\/\\//\//\\\/\\/\/</span><span class="w">
</span><span class="c1">#> ////\\\////\/\\\\\/////\/\\\////\\///\\\</span><span class="w">
</span><span class="c1">#> \//\\\//\///\/\\\\//\\\////\\//\\/\/\//\</span><span class="w">
</span><span class="c1">#> \/\//\\//\\///\\\\\\//\///\/\\\\\\\\/\\/</span><span class="w">
</span><span class="c1">#> ///\/\//\\/\/\\\\\\\\/\///\//\\///\\//\\</span><span class="w">
</span><span class="c1">#> /////\\///\/\\/\/\\//\\//\/\\/\//\//\\\\</span><span class="w">
</span>

where withr::with_options() lets us temporarily change the print width and
cat() concatenates the slashes and prints out the characters as text.

We can also make this much prettier by drawing the patterns using ggplot2.

Drawing line segments with ggplot2

Instead of writing out slashes, we will draw a grid of diagonal line segments,
some of which will be flipped at random. To draw a segment, we need a starting
xy coordinate and an ending xy coordinate. geom_segment() will
connect the two coordinates with a line. Here’s a small example where we draw
four “slashes”.

<span class="n">library</span><span class="p">(</span><span class="n">ggplot2</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">dplyr</span><span class="p">)</span><span class="w">

</span><span class="n">data</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tibble</span><span class="o">::</span><span class="n">tribble</span><span class="p">(</span><span class="w">
  </span><span class="o">~</span><span class="n">row</span><span class="p">,</span><span class="w"> </span><span class="o">~</span><span class="n">col</span><span class="p">,</span><span class="w"> </span><span class="o">~</span><span class="n">x_start</span><span class="p">,</span><span class="w"> </span><span class="o">~</span><span class="n">x_end</span><span class="p">,</span><span class="w"> </span><span class="o">~</span><span class="n">y_start</span><span class="p">,</span><span class="w"> </span><span class="o">~</span><span class="n">y_end</span><span class="p">,</span><span class="w">
     </span><span class="m">1</span><span class="p">,</span><span class="w">    </span><span class="m">1</span><span class="p">,</span><span class="w">        </span><span class="m">0</span><span class="p">,</span><span class="w">      </span><span class="m">1</span><span class="p">,</span><span class="w">        </span><span class="m">0</span><span class="p">,</span><span class="w">      </span><span class="m">1</span><span class="p">,</span><span class="w">
     </span><span class="m">1</span><span class="p">,</span><span class="w">    </span><span class="m">2</span><span class="p">,</span><span class="w">        </span><span class="m">1</span><span class="p">,</span><span class="w">      </span><span class="m">2</span><span class="p">,</span><span class="w">        </span><span class="m">1</span><span class="p">,</span><span class="w">      </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="c1"># flipped</span><span class="w">
     </span><span class="m">2</span><span class="p">,</span><span class="w">    </span><span class="m">1</span><span class="p">,</span><span class="w">        </span><span class="m">0</span><span class="p">,</span><span class="w">      </span><span class="m">1</span><span class="p">,</span><span class="w">        </span><span class="m">1</span><span class="p">,</span><span class="w">      </span><span class="m">2</span><span class="p">,</span><span class="w">
     </span><span class="m">2</span><span class="p">,</span><span class="w">    </span><span class="m">2</span><span class="p">,</span><span class="w">        </span><span class="m">1</span><span class="p">,</span><span class="w">      </span><span class="m">2</span><span class="p">,</span><span class="w">        </span><span class="m">1</span><span class="p">,</span><span class="w">      </span><span class="m">2</span><span class="p">)</span><span class="w">
  
</span><span class="n">ggplot</span><span class="p">(</span><span class="n">data</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_start</span><span class="p">,</span><span class="w"> </span><span class="n">xend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_end</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_start</span><span class="p">,</span><span class="w"> </span><span class="n">yend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_end</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">geom_segment</span><span class="p">()</span><span class="w">
</span>

A simple demo of geom_segment()

The programming task now is to make giant grid of these slashes. Let’s start
with an observation: To draw two slashes, we needed three x
values: 0, 1, 2. The first two served as segment starts and the last two
as segment ends. The same idea applies to the y values. We can generate a
bunch of starts and ends by taking a sequence of steps and removing the first
and last elements.

<span class="c1"># We want a 20 by 20 grid</span><span class="w">
</span><span class="n">rows</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="m">20</span><span class="w">
</span><span class="n">cols</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="m">20</span><span class="w">

</span><span class="n">x_points</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">)</span><span class="w">
</span><span class="n">x_starts</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">head</span><span class="p">(</span><span class="n">x_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">
</span><span class="n">x_ends</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tail</span><span class="p">(</span><span class="n">x_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">

</span><span class="n">y_points</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rows</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">)</span><span class="w">
</span><span class="n">y_starts</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">head</span><span class="p">(</span><span class="n">y_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">
</span><span class="n">y_ends</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tail</span><span class="p">(</span><span class="n">y_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">
</span>

Each x_startsx_ends pair is a column in the grid, and each
y_startsy_ends is a row in the grid. To make a slash at each
row–column combination, we have to map out all the combinations of the rows
and columns. We can do this with crossing() which creates all crossed
combinations of values. (If it helps, you might think of crossed like crossed
experiments
or the
Cartesian cross product of
sets.)

<span class="n">grid</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tidyr</span><span class="o">::</span><span class="n">crossing</span><span class="p">(</span><span class="w">
  </span><span class="c1"># columns</span><span class="w">
  </span><span class="n">data_frame</span><span class="p">(</span><span class="n">x_start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_starts</span><span class="p">,</span><span class="w"> </span><span class="n">x_end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_ends</span><span class="p">),</span><span class="w">
  </span><span class="c1"># rows</span><span class="w">
  </span><span class="n">data_frame</span><span class="p">(</span><span class="n">y_start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_starts</span><span class="p">,</span><span class="w"> </span><span class="n">y_end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_ends</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
  </span><span class="c1"># So values move left to right, bottom to top</span><span class="w">
  </span><span class="n">arrange</span><span class="p">(</span><span class="n">y_start</span><span class="p">,</span><span class="w"> </span><span class="n">y_end</span><span class="p">)</span><span class="w">

</span><span class="c1"># 400 rows because 20 rows x 20 columns</span><span class="w">
</span><span class="n">grid</span><span class="w">
</span><span class="c1">#> # A tibble: 400 x 4</span><span class="w">
</span><span class="c1">#>    x_start x_end y_start y_end</span><span class="w">
</span><span class="c1">#>      <dbl> <dbl>   <dbl> <dbl></span><span class="w">
</span><span class="c1">#>  1    0     0.05       0  0.05</span><span class="w">
</span><span class="c1">#>  2    0.05  0.1        0  0.05</span><span class="w">
</span><span class="c1">#>  3    0.1   0.15       0  0.05</span><span class="w">
</span><span class="c1">#>  4    0.15  0.2        0  0.05</span><span class="w">
</span><span class="c1">#>  5    0.2   0.25       0  0.05</span><span class="w">
</span><span class="c1">#>  6    0.25  0.3        0  0.05</span><span class="w">
</span><span class="c1">#>  7    0.3   0.35       0  0.05</span><span class="w">
</span><span class="c1">#>  8    0.35  0.4        0  0.05</span><span class="w">
</span><span class="c1">#>  9    0.4   0.45       0  0.05</span><span class="w">
</span><span class="c1">#> 10    0.45  0.5        0  0.05</span><span class="w">
</span><span class="c1">#> # ... with 390 more rows</span><span class="w">
</span>

We can confirm that the segments in the grid fill out a plot. (I
randomly color the line segments to make individual ones visible.)

<span class="n">ggplot</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">aes</span><span class="p">(</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_start</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_start</span><span class="p">,</span><span class="w"> 
    </span><span class="n">xend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_end</span><span class="p">,</span><span class="w"> </span><span class="n">yend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_end</span><span class="p">,</span><span class="w"> 
    </span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">runif</span><span class="p">(</span><span class="m">400</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">geom_segment</span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">guides</span><span class="p">(</span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">FALSE</span><span class="p">)</span><span class="w">
</span>

A grid full of line segments, all pointing the same direction

Finally, we need to flip slashes at random. A segment becomes flipped if the
y_start and y_end are swapped. In the code below, we flip the slash in each
row if a randomly drawn number between 0 and 1 is less than .5. For style, we
also use theme_void() to strip away the plotting theme, leaving us with just
the maze design.

<span class="n">p_flip</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="m">.5</span><span class="w">

</span><span class="n">grid</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">grid</span><span class="w"> </span><span class="o">%>%</span><span class="w">
  </span><span class="n">arrange</span><span class="p">(</span><span class="n">y_start</span><span class="p">,</span><span class="w"> </span><span class="n">y_end</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">mutate</span><span class="p">(</span><span class="w">
    </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">,</span><span class="w">
    </span><span class="n">flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">runif</span><span class="p">(</span><span class="nf">length</span><span class="p">(</span><span class="n">y_end</span><span class="p">))</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">,</span><span class="w">
    </span><span class="n">y_temp1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_start</span><span class="p">,</span><span class="w">
    </span><span class="n">y_temp2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_end</span><span class="p">,</span><span class="w">
    </span><span class="n">y_start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ifelse</span><span class="p">(</span><span class="n">flip</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp2</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp1</span><span class="p">),</span><span class="w">
    </span><span class="n">y_end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ifelse</span><span class="p">(</span><span class="n">flip</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp1</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp2</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
  </span><span class="n">select</span><span class="p">(</span><span class="n">x_start</span><span class="o">:</span><span class="n">y_end</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="p">)</span><span class="w">

</span><span class="n">ggplot</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_start</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_start</span><span class="p">,</span><span class="w"> </span><span class="n">xend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_end</span><span class="p">,</span><span class="w"> </span><span class="n">yend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_end</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">geom_segment</span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"grey20"</span><span class="p">)</span><span class="w"> 

</span><span class="n">last_plot</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">theme_void</span><span class="p">()</span><span class="w">
</span>

A maze with 50% flipping probabilityA maze with 50% flipping probability

Now, we wrap all these steps together into a pair of functions.

<span class="n">make_10_print_data</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">20</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">20</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.5</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="n">x_points</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">)</span><span class="w">
  </span><span class="n">x_starts</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">head</span><span class="p">(</span><span class="n">x_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">
  </span><span class="n">x_ends</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tail</span><span class="p">(</span><span class="n">x_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">
  
  </span><span class="n">y_points</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rows</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">)</span><span class="w">
  </span><span class="n">y_starts</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">head</span><span class="p">(</span><span class="n">y_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">
  </span><span class="n">y_ends</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tail</span><span class="p">(</span><span class="n">y_points</span><span class="p">,</span><span class="w"> </span><span class="m">-1</span><span class="p">)</span><span class="w">

  </span><span class="n">grid</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tidyr</span><span class="o">::</span><span class="n">crossing</span><span class="p">(</span><span class="w">
    </span><span class="n">data.frame</span><span class="p">(</span><span class="n">x_start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_starts</span><span class="p">,</span><span class="w"> </span><span class="n">x_end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_ends</span><span class="p">),</span><span class="w">
    </span><span class="n">data.frame</span><span class="p">(</span><span class="n">y_start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_starts</span><span class="p">,</span><span class="w"> </span><span class="n">y_end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_ends</span><span class="p">))</span><span class="w">

  </span><span class="n">grid</span><span class="w"> </span><span class="o">%>%</span><span class="w">
    </span><span class="n">arrange</span><span class="p">(</span><span class="n">y_start</span><span class="p">,</span><span class="w"> </span><span class="n">y_end</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
    </span><span class="n">mutate</span><span class="p">(</span><span class="w">
      </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">,</span><span class="w">
      </span><span class="n">flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">runif</span><span class="p">(</span><span class="nf">length</span><span class="p">(</span><span class="n">y_end</span><span class="p">))</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">,</span><span class="w">
      </span><span class="n">y_temp1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_start</span><span class="p">,</span><span class="w">
      </span><span class="n">y_temp2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_end</span><span class="p">,</span><span class="w">
      </span><span class="n">y_start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ifelse</span><span class="p">(</span><span class="n">flip</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp2</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp1</span><span class="p">),</span><span class="w">
      </span><span class="n">y_end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ifelse</span><span class="p">(</span><span class="n">flip</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp1</span><span class="p">,</span><span class="w"> </span><span class="n">y_temp2</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
    </span><span class="n">select</span><span class="p">(</span><span class="n">x_start</span><span class="o">:</span><span class="n">y_end</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">draw_10_print</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">20</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">20</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.5</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="n">grid</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">make_10_print_data</span><span class="p">(</span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rows</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cols</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">)</span><span class="w">

  </span><span class="n">ggplot</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_start</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_start</span><span class="p">,</span><span class="w"> </span><span class="n">xend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x_end</span><span class="p">,</span><span class="w"> </span><span class="n">yend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y_end</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">geom_segment</span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"grey20"</span><span class="p">)</span><span class="w"> 
</span><span class="p">}</span><span class="w">
</span>

Now the fun part: custom flipping probabilities

We can vary the probability of flipping the slashes. For example, we can use the
density of a normal distribution to make flipping more likely for central values
and less likely for more extreme values.

<span class="n">xs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">)</span><span class="w">
</span><span class="n">p_flip</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">dnorm</span><span class="p">(</span><span class="n">seq</span><span class="p">(</span><span class="m">-4</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">))</span><span class="w">

</span><span class="n">ggplot</span><span class="p">(</span><span class="n">data.frame</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">xs</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">geom_line</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">labs</span><span class="p">(</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"x position"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"p(flipping)"</span><span class="p">,</span><span class="w">
    </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"normal density"</span><span class="p">)</span><span class="w">

</span><span class="c1"># We repeat p_flip for each row of the grid</span><span class="w">
</span><span class="n">draw_10_print</span><span class="p">(</span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">rep</span><span class="p">(</span><span class="n">p_flip</span><span class="p">,</span><span class="w"> </span><span class="m">40</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">theme_void</span><span class="p">()</span><span class="w">
</span>

Density of the normal distributionA maze where flipping probability is based on the density of a normal curve

We can use the cumulative density of the normal distribution so that
flipping becomes more likely as x increases.

<span class="n">xs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">)</span><span class="w">
</span><span class="n">p_flip</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">pnorm</span><span class="p">(</span><span class="n">seq</span><span class="p">(</span><span class="m">-4</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">))</span><span class="w">

</span><span class="n">ggplot</span><span class="p">(</span><span class="n">data.frame</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">xs</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">geom_line</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">labs</span><span class="p">(</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"x position"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"p(flipping)"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"cumulative normal"</span><span class="p">)</span><span class="w">

</span><span class="n">draw_10_print</span><span class="p">(</span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">rep</span><span class="p">(</span><span class="n">p_flip</span><span class="p">,</span><span class="w"> </span><span class="m">40</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">theme_void</span><span class="p">()</span><span class="w">
</span>

Cumulative density of the normal distributionA maze where flipping probability is based on the cumulative density of a normal curve

The Cauchy distribution is said to have “thicker” tails than the normal
distribution, so here it shows more flips on the left and right extremes.

<span class="n">xs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">)</span><span class="w">
</span><span class="n">p_flip</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">dcauchy</span><span class="p">(</span><span class="n">seq</span><span class="p">(</span><span class="m">-4</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">))</span><span class="w">

</span><span class="n">ggplot</span><span class="p">(</span><span class="n">data.frame</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">xs</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">geom_line</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">labs</span><span class="p">(</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"x position"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"p(flipping)"</span><span class="p">,</span><span class="w">
    </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Cauchy density"</span><span class="p">)</span><span class="w">

</span><span class="n">draw_10_print</span><span class="p">(</span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">rep</span><span class="p">(</span><span class="n">p_flip</span><span class="p">,</span><span class="w"> </span><span class="m">40</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">theme_void</span><span class="p">()</span><span class="w">
</span>

Density of the Cauchy distributionA maze where flipping probability is based on the density of a Cauchy curve

The exponential distribution is a spike that quickly peters out. We can make a
probability “bowl” by splicing an exponential and a reversed exponential
together.

<span class="c1"># Use flipped exponential densities as probabilities</span><span class="w">
</span><span class="n">p_flip</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="n">dexp</span><span class="p">(</span><span class="n">seq</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">20</span><span class="p">)),</span><span class="w">
            </span><span class="n">dexp</span><span class="p">(</span><span class="n">seq</span><span class="p">(</span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="n">length.out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">20</span><span class="p">)))</span><span class="w">

</span><span class="n">ggplot</span><span class="p">(</span><span class="n">data.frame</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">xs</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_flip</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">geom_line</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">labs</span><span class="p">(</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"x position"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"p(flipping)"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"exponential + flipped exponential"</span><span class="p">)</span><span class="w">

</span><span class="n">draw_10_print</span><span class="p">(</span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">rep</span><span class="p">(</span><span class="n">p_flip</span><span class="p">,</span><span class="w"> </span><span class="m">40</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">theme_void</span><span class="p">()</span><span class="w"> 
</span>

Densities of two exponential curves spliced to form a bowlA maze where flipping probability is based on an exponential curve and a reversed exponential curve

We might have the probabilities increase by 10% from row to row. In the code
below, I use a simple loop to boost some random probability values by 10% from
row to row. This gives us nice streaks in the grid as a column starts to flip
for every row.

<span class="n">boost_probs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">p_flip</span><span class="p">,</span><span class="w"> </span><span class="n">nrows</span><span class="p">,</span><span class="w"> </span><span class="n">factor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1.1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="n">output</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">p_flip</span><span class="w">
  </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nf">seq_len</span><span class="p">(</span><span class="n">nrows</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="n">p_flip</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">p_flip</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">factor</span><span class="w">
    </span><span class="n">output</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="n">output</span><span class="p">,</span><span class="w"> </span><span class="n">p_flip</span><span class="p">)</span><span class="w">
  </span><span class="p">}</span><span class="w">
  </span><span class="n">output</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">draw_10_print</span><span class="p">(</span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">boost_probs</span><span class="p">(</span><span class="n">runif</span><span class="p">(</span><span class="m">40</span><span class="p">),</span><span class="w"> </span><span class="m">40</span><span class="p">,</span><span class="w"> </span><span class="m">1.1</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">theme_void</span><span class="p">()</span><span class="w">
</span>

A maze where flipping probability increases by 10% from row to row

The probabilities can be anything we like. Here I compute the frequency of
English alphabet letters as they appear in Pride and Prejudice and based the
flipping probability on those values.

<span class="n">char_counts</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">janeaustenr</span><span class="o">::</span><span class="n">prideprejudice</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">tolower</span><span class="p">()</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">stringr</span><span class="o">::</span><span class="n">str_split</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">unlist</span><span class="p">()</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">table</span><span class="p">()</span><span class="w">

</span><span class="n">letter_counts</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">char_counts</span><span class="p">[</span><span class="nb">letters</span><span class="p">]</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">as.vector</span><span class="p">()</span><span class="w">
</span><span class="n">p_letter</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">letter_counts</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="nf">sum</span><span class="p">(</span><span class="n">letter_counts</span><span class="p">)</span><span class="w">

</span><span class="n">ggplot</span><span class="p">(</span><span class="n">data.frame</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">letters</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p_letter</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">,</span><span class="w"> </span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> 
  </span><span class="n">geom_text</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">labs</span><span class="p">(</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">NULL</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"p(letter)"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"letter frequencies in Pride and Prejudice"</span><span class="p">)</span><span class="w">
</span>

Letter frequencies in Pride and Prejudice

<span class="n">draw_10_print</span><span class="p">(</span><span class="n">cols</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">26</span><span class="p">,</span><span class="w"> </span><span class="n">rows</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">80</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">rep</span><span class="p">(</span><span class="n">p_letter</span><span class="p">,</span><span class="w"> </span><span class="m">80</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
 </span><span class="n">theme_void</span><span class="p">()</span><span class="w"> 
</span>

Maze where flipping frequency is based on letter frequencies in Pride and Prejudice

To leave a comment for the author, please follow the link and comment on their blog: Higher Order Functions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)