Skip to content

Line with linearly changing thickness – installation issues

1 message · John Fox

#
And here's a simpler, loopless version:

tlines <- function(x, y, thickness, col="black", unit=0.005){
    # line of varying thickness
    #   x: vector of x coordinates
    #   y: vector of y coordinates
    #   thickness: units of thickness at each set of coordinates
    #   col: line colour
    #   unit: unit of thickness as fraction of vertical axis
    if (length(x) != length(y)) "x and y are of different lengths"
    if (length(x) != length(thickness)) 
        "length of thickness is different from x and y"
    if (length(x) < 2) "x and y are too short"
    usr <- par("usr")
    units <- (usr[4] - usr[3])*unit/2
    x <- c(x, rev(x))
    y <- c(y + thickness*units, rev(y) - rev(thickness)*units)
    polygon(x=x, y=y, col=col, border=col)
}

Best,
 John