# required packages
# install.packages("ggplot2")
library(ggplot2)
library(dplyr)
Preparation: Generative aRt
For Session 2
This exercise is not graded, and you can try it on your own, as a test of whether you understood everything we did in class so far.
Packages
The exercise requires having installed the R package ggplot2
.
Example 1
Execute the following code. Something should appear in the ʻPlotsʼ pane.
seq(from = -5, to = 10, by = 0.05) %>%
expand.grid(x = ., y = .) %>%
ggplot(aes(x = (x + pi * sin(y)), y = (y + pi * sin(x)))) +
geom_point(alpha = .1, shape = 20, size = 1, color = "darkred")+
coord_polar() +
theme_void()
Example 2
Execute the rest of the code — one more plot should appear.
seq(1, 200, .0005) %>%
tibble(x = exp(-0.006 * .) * sin(. * 3.01 + 1.68) + sin(. * 2.96 + 2.72),
y = exp(-0.009 * .) * sin(. * 3.03 + 1.23) + sin(. * 2.98 + 1.28)) %>%
ggplot(aes(x, y)) +
geom_path(linewidth = 1/3, color = "steelblue")+
coord_equal() +
theme_void()
Source
Antonio Sánchez Chinchón, on Twitter: example 1, example 2, very slightly tweaked. A lot of his examples are also available on GitHub.
Relevant Twitter hashtags to find more examples: #rstats
#generativeart
#ggplot2
.