[R] par("uin") ?

Michael Friendly friendly at yorku.ca
Mon Jul 19 17:20:00 CEST 2010


I inherited a function written either for an older version of R or SPlus
to draw a brace, "{", in a graph.  It uses par("uin") to determine the 
scaling of the
quarter circles that make up segments of the brace,  but that setting 
doesn't
exist in current R.
I'm guessing that, in the function below, ux, uy can be defined from
par("usr") and par("pin"), but maybe someone remembers what par("uin")
was supposed to refer to.

brace <- function (x1 = 0, y1 = 0, x2 = 0, y2 = 1, right = TRUE, rad = 0.2)
{
    uin <- par("uin")
    ux <- uin[1]
    uy <- uin[2]
    dx <- x2 - x1
    dy <- y2 - y1
    alpha <- atan(ux * dx, uy * dy)
    scale <- sqrt((ux * dx)^2 + (uy * dy)^2)
    if (scale > 5 * rad)
        rad <- rad/scale
    qcirc <- cbind(cos((0:10) * pi/20), sin((0:10) * pi/20))
    qcircr <- cbind(cos((10:0) * pi/20), sin((10:0) * pi/20))
    rot <- function(theta) t(cbind(c(cos(theta), sin(theta)),
        c(-sin(theta), cos(theta))))
    seg1 <- t(t(rad * qcirc %*% rot(-pi/2)) + c(0, rad))
    seg4 <- t(t(rad * qcirc) + c(0, 1 - rad))
    seg3 <- t(t((rad * qcircr) %*% rot(pi)) + c(2 * rad, 0.5 +
        rad))
    seg2 <- t(t((rad * qcircr) %*% rot(pi/2)) + c(2 * rad, 0.5 -
        rad))
    bra <- rbind(seg1, seg2, seg3, seg4)
    if (!right)
        bra <- bra %*% diag(c(-1, 1))
    bra <- scale * bra %*% rot(-alpha)
    bra <- bra %*% diag(c(1/ux, 1/uy))
    bra <- t(t(bra) + c(x1, y1))
    bra
}

-- 
Michael Friendly     Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list