The required library
require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.2
Load the library ggplot2
library(ggplot2)
Create the data
dat <- data.frame(t = seq(0, 2*pi, by = 0.01))
x <- function(t) 16 * sin(t)^3
y <- function(t) 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)
View the data
head(x)
##
## 1 function (t)
## 2 16 * sin(t)^3
head(y)
##
## 1 function (t)
## 2 13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)
tail(x)
##
## 1 function (t)
## 2 16 * sin(t)^3
tail(y)
##
## 1 function (t)
## 2 13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)
dat$y <- y(dat$t)
dat$x <- x(dat$t)
head(y)
##
## 1 function (t)
## 2 13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)
head(x)
##
## 1 function (t)
## 2 16 * sin(t)^3
Draw the heart image
heart <- ggplot(dat, aes(x,y)) +
geom_polygon(fill = "red", col = "firebrick", alpha = 0.8) +
theme_classic()
heart
