Created
April 2, 2024 07:22
-
-
Save abikoushi/42ee3652f2995e306229ba810f3af56a to your computer and use it in GitHub Desktop.
Andrews' curve using geom_function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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