-3

I have found a Matlab script to generate a scatterplot in heart shape, however, I would like to draw this plot in R.

http://scriptdemo.blogspot.co.at/2013/02/show-normal-random-heart.html

Could somebody help me to interpret or transform the code so that I can use it in R?

Thanks in advance, Philipp

user3485328
  • 41
  • 1
  • 4
  • 3
    Did you make any attempt? Please include the code you tried and describe exactly where you are having difficulties. – MrFlick Dec 19 '14 at 17:06
  • 5
    That's an amusing variation on the "Plot a heart theme": http://stackoverflow.com/questions/8082429/plot-a-heart-in-r/8082714#8082714 – IRTFM Dec 19 '14 at 17:12

1 Answers1

6

This seems to be a fairly basic translation

r <- 0.618
n <- 10000
re <- sqrt(1-r*r);
x <- rnorm(n);
y <- x*r+rnorm(n)*re
y[x<0] <- -y[x<0];

par(mar=rep(0,4))
plot(x,y, col=rgb(1,0,1), axes=F, asp=1)

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • I ran down the rabbit hole of thinking this need Matplot's handling of imaginary numbers. Didn't recognize that it was just flipping a normal distribution in the `x<0` half-plane. – IRTFM Dec 19 '14 at 17:28