There are so many beautiful “π” arts everywhere, and I wanted to practice ggplot2 by mimicing those arts further more. Another pi art caught my eye is random walk of pi digits. Here’s one of examples in WIRED magazine.
For random walk to work, I’ve assigned direction to “walk” depending on digits 0-9.
I’ve prepared data frame as below, so I can use ggplot2 to plot
1 |
|
0 | 3 | 1.8849556 | 108 | -0.309017 | 0.9510565 | 0.000000 | 0.0000000 | -0.309017 | 0.9510565 | 0.000000 | 0.0000000 |
1 | 1 | 0.6283185 | 36 | 0.809017 | 0.5877853 | -0.309017 | 0.9510565 | 0.500000 | 1.5388418 | -0.309017 | 0.9510565 |
2 | 4 | 2.5132741 | 144 | -0.809017 | 0.5877853 | 0.809017 | 0.5877853 | -0.309017 | 2.1266270 | 0.500000 | 1.5388418 |
3 | 1 | 0.6283185 | 36 | 0.809017 | 0.5877853 | -0.809017 | 0.5877853 | 0.500000 | 2.7144123 | -0.309017 | 2.1266270 |
4 | 5 | 3.1415927 | 180 | -1.000000 | 0.0000000 | 0.809017 | 0.5877853 | -0.500000 | 2.7144123 | 0.500000 | 2.7144123 |
Now to visualize the random walk, I’ve used below script to visualize first 1000, first 10000 and first 100000 digits of pi.
1 |
|
1 |
|
1 |
|
Related