In case you’ve ever wondered how to graph a heart in R, I’ve figured it out for you. No need to thank me.
Maybe it could be featured on a nerdy valentine?
The Equations
The R Code
###Filled Heart
##Plot the top
top <- function(x) (1-(abs(x)-1)^2)^.5
pink <- rgb(201, 6, 45, max = 255) #set color
plot(top, xlim=c(-2,2), ylim=c(-3,1),
ylab="y", col=pink, main="Heart")
##Plot the v par(new=TRUE) v <- function(x) -3*(1-(abs(x)/2)^.5)^.5 plot(v, xlim=c(-2,2), ylim=c(-3,1), ylab="y", col=pink)
##Fill the Graph top.x <- seq(-2,2, .01) #x coordinates for top v.x <- seq(-2,2, .01) #x coordinates for v top.y <- top(v.x) #y coordinates for top v.y <- v(v.x) #y coordinates for v x <- c(v.x, rev(top.x)) #put the coordinates together y <- c(v.y, rev(top.y)) polygon(x, y, col=pink, border=pink)
Nice work! Those equations took me back to my college days 🙂
LikeLiked by 1 person
Your analytical mind never ceases to amaze me!!!!!!
LikeLiked by 1 person
You’re too nice!
LikeLike