rm(list = ls())
# ggplot2
library(pacman)
## Warning: package 'pacman' was built under R version 4.0.3
p_load(ggplot2)

# 50 points on a circle with radius 1
t <- seq(0, 2*pi, length.out = 50)
x <- sin(t)
y <- cos(t)
df <- data.frame(t, x, y)
p <- ggplot(df, aes(x, y))
p + geom_point()

# Scatter plot based on golden angle spiral arrangement
points <- 500
angle <- pi * (3 - sqrt(5)) # angle calculation formula
t <- (1:points) * angle
x <- sin(t)
y <- cos(t)
df <- data.frame(t, x, y)
p <- ggplot(df, aes(x*t, y*t))
p + geom_point()

# Image modification
p <- ggplot(df, aes(x*t, y*t))
p + geom_point(size=8, alpha=0.5, color="darkgreen") + 
  theme(
    panel.grid = element_blank(),
    axis.ticks = element_blank(),
    title = element_blank(),
    text = element_blank(),
    panel.background = element_rect(fill = "white")
  )

# Dandelion
p <- ggplot(df, aes(x*t, y*t))
p + geom_point(aes(size = t), alpha = 0.5, shape = 8, color = "black") +
  theme(
    panel.grid = element_blank(),
    axis.ticks = element_blank(),
    title = element_blank(),
    text = element_blank(),
    panel.background = element_rect(fill = "white"),
    legend.position = "none"
  )

# sunflower
p <- ggplot(df, aes(x*t, y*t))
p + geom_point(aes(size = t), alpha = 0.5, shape = 17, color = "yellow") +
  theme(
    panel.grid = element_blank(),
    axis.ticks = element_blank(),
    title = element_blank(),
    text = element_blank(),
    panel.background = element_rect(fill = "darkmagenta"),
    legend.position = "none"
  )

angle <- 2.0
points <- 1000

t <- (1:points)*angle
x <- sin(t)
y <- cos(t)

df <- data.frame(t, x, y)

p <- ggplot(df, aes(x*t, y*t))
p + geom_point(aes(size = t), alpha = 0.5, shape = 17, color = "yellow") +
  theme(
    panel.grid = element_blank(),
    axis.ticks = element_blank(),
    title = element_blank(),
    text = element_blank(),
    panel.background = element_rect(fill = "darkmagenta"),
    legend.position = "none"
  )