Suppose there is this function sqrt(x^2)+0.9*sqrt(3.3-x^2)*sin(30*pi*x) This function generate plot in the shape of a heart
Is there the way using ggplot2 reproduce this function to get a red heart as output?
Thanks you for your help.
>Solution :
You will get better resolution if you directly calculate along a predefined sequence. Also, the formula is not quite right, so I have amended it:
heart <- function(x) abs(x)^(2/3) + 0.9 * sqrt(3.3 - x^2) * sin(18 * pi * x)
df <- data.frame(x = seq(-sqrt(3.3), sqrt(3.3), length = 3000),
y = heart(seq(-sqrt(3.3), sqrt(3.3), length = 3000)))
ggplot(df, aes(x, y)) +
geom_line(size = 1, colour = "red") +
scale_x_continuous(limits = c(-2, 2)) +
coord_equal() +
theme_void() +
theme(plot.background = element_rect(fill = "#400000"))

