浪漫的表白与猥琐的相思——几个有趣的R代码

  1. 此图代表我的心

  2. 1
    2
    3
    4
    5
    6
    
    n=50000;
    r=0.7;r_e=(1-r*r)^.5;
    X=rnorm(n);
    Y=X*r+r_e*rnorm(n);
    Y=ifelse(X>0,Y,-Y);
    plot(X,Y,col="pink")

    pink_heart

  3. 我心因你而有爱

  4. 1
    2
    3
    4
    5
    6
    7
    8
    9
    
    n=50000;
    r=0.7;r_e=(1-r*r)^.5;
    X=rnorm(n);
    Y=X*r+r_e*rnorm(n);
    Y=ifelse(X>0,Y,-Y);
    a<-sample(c(2,6,7,8),50000,T)
    b<-sample(c(76,79,86,69),50000,T)
    plot(X,Y,col=0)
    text(X,Y,"lOVE",col=a)

    love_heart

  5. 一切尽在不言中

  6. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    xrange = c(-15, 15)
    yrange = c(0, 16)
    plot(0, xlim = xrange, ylim = yrange, type = "n")
    #plot(xrange, yrange, type="n", ann=FALSE, axes=FALSE)
    yr = seq(yrange[1], yrange[2], len = 50)
    offsetFn = function(y) {
    2 * sin(0 + y/3)
    }
    offset = offsetFn(yr)
    leftE = function(y) {
    -10 - offsetFn(y)
    }
    rightE = function(y) {
    10 + offsetFn(y)
    }
    xp = c(leftE(yr), rev(rightE(yr)))
    yp = c(yr, rev(yr))
    polygon(xp, yp, col = "#ffeecc", border = NA)
    h = 9
    xt = seq(0, rightE(h), len = 100)
    yt = log(1 + log(1 + log(xt + 1)))
    yt = yt - min(yt)
    yt = h * yt/max(yt)
    x = c(leftE(h), rightE(h), rev(xt), -xt)
    y = c(h, h, rev(yt), yt)
    polygon(x, y, col = "red", border = NA)

    woman1 woman2

  7. 资料来源

  8. R语言 浪漫的R代码
    网上惊现流氓R代码!