Possible Duplicate:
Equation-driven smoothly shaded concentric shapes
How could I plot a symmetrical heart in R like I plot a circle (using plotrix) or a rectangle?
I'd like code for this so that I could actually do it for my self and to be able to generalize this to similar future needs. I've seen even more elaborate plots than this so it's pretty doable, it's just that I lack the knowledge to do it.
Here is a cardioid in
ggplot
:And the heart plot (linked by @BenBolker):
This is an example of plotting a "parametric equation", i.e. a pairing of two separate equations for x and y that share a common parameter. You can find many common curves and shapes that can be written within such a framework.
Other Parametric (and implicit and polar) Heart Eqns
You also could "heat it up" with using the "fill" capability of the
polygon
function:And if you just want little hearts to sprinkle around at various places, you could use the Symbol font version of "heart" after looking at the
help(points)
page and using theTestChars
function:Windows users may want to see if adding the Cairo package helps gain access to card symbols including "hearts".( When I tested the TestChars function on the WinXP "side" of my MacPro I did not get hearts, and paging through the "special symbols" in MS-Word did not uncover anything. So I did a search of Rhelp and found a recent posting by Ivo Welch. He was reporting a bug, but they look OK on my machine.) Further note... I think the hearts and diamonds codes in his were reversed.
If you want to be more "mature", try out the following (posted to R-help a few years ago):
Another option,
Simple and ugly hack:
From a blog post:
Solve the parametric equation for y (does SO allow math formatting?)
x^2 + (5y/4-sqrt(abs(x)))^2 = 1
sqrt(1-x^2) = 5y/4 - sqrt(abs(x))
y = 4/5*(sqrt(1-x^2)+sqrt(abs(x)))