Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created April 2, 2024 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abikoushi/42ee3652f2995e306229ba810f3af56a to your computer and use it in GitHub Desktop.
Save abikoushi/42ee3652f2995e306229ba810f3af56a to your computer and use it in GitHub Desktop.
Andrews' curve using geom_function
library(ggplot2)
library(dplyr)
Andrews <- function(t,
Sepal.Length, Sepal.Width,
Petal.Length, Petal.Width,...){
root2 <- sqrt(2)
sapply(t, function(t){Sepal.Length/root2 +
Sepal.Width*sin(t) +
Petal.Length*cos(t) +
Petal.Width*sin(2*t)})
}
layer_fun <- lapply(row_number(iris),
function(i)geom_function(data=iris[i,],
fun=Andrews,
args=as.list(iris[i,1:4]),
aes(colour = Species)))
ggplot() +
layer_fun+
xlim(-pi, pi)
ggsave("andrews.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment