[R] Line with linearly changing thickness – installation issues

Fox, John jfox @ending from mcm@@ter@c@
Sun Nov 11 20:53:12 CET 2018


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

> -----Original Message-----
> From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of Fox, John
> Sent: Sunday, November 11, 2018 1:30 PM
> To: David Winsemius <dwinsemius using comcast.net>; Ferri Leberl
> <ferri.leberl using gmx.at>
> Cc: r-help using r-project.org
> Subject: Re: [R] Line with linearly changing thickness – installation issues
> 
> Dear David and Ferri,
> 
> Here's a simple implementation using polygon() (as David suggested). It's
> much less sophisticated than Paul Murrell's -- in particular, the ends of the line
> are simply vertical (but, with a bit more work, that too could be addressed) --
> and uses standard R graphics rather than grid.
> 
> tline <- 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
>     tl <- function(x1, x2, y1, y2, start, end){
>         polygon(x=c(x1, x1, x2, x2, x1),
>                 y=c(y1 - start*units, y1 + start*units,
>                     y2 + end*units, y2 - end*units,
>                     y1 - start*units),
>                 col=col, border=col)
>     }
>     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
>     for (i in 2:length(x)){
>         tl(x[i - 1], x[i], y[i - 1], y[i], thickness[i - 1], thickness[i])
>     }
> }
> 
> # example:
> 
> plot(c(-1, 1), c(0, 100), type="n")
> tline(seq(-1, 1, by=0.1), y=(seq(1, 9.5, length=21))^2,
>       thickness=seq(1, 20, length=21), col="blue")
> 
> I hope this helps,
>  John
> 
> --------------------------------------
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> Web: socialsciences.mcmaster.ca/jfox/
> 
> 
> 
> > -----Original Message-----
> > From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of David
> > Winsemius
> > Sent: Sunday, November 11, 2018 12:23 PM
> > To: r-help using r-project.org
> > Subject: Re: [R] Line with linearly changing thickness – installation
> > issues
> >
> > I would have imagined that drawing a polygon would be the way most
> > people would have attempted.
> >
> > Regarding Murrell's package:
> >
> > I thought the package name was "vwline". My attempt to install was
> > unsuccessful>
> >
> >  > devtools::install_github("pmur002/vwline")
> > Error in utils::download.file(url, path, method = download_method(),
> > quiet = quiet,  :
> >    cannot open URL
> > 'https://api.github.com/repos/pmur002/vwline/contents/DESCRIPTION?ref=
> > ma
> > ster'
> >  > install.packages("~/vwline-0.2-1.tar.gz", repo=NULL) Installing
> > package into ‘/home/david/R/x86_64-pc-linux-gnu-library/3.5.1’
> > (as ‘lib’ is unspecified)
> > Warning in untar2(tarfile, files, list, exdir, restore_times) :
> >    skipping pax global extended headers
> > ERROR: cannot extract package from ‘/home/david/vwline-0.2-1.tar.gz’
> > Warning in install.packages :
> >    installation of package ‘/home/david/vwline-0.2-1.tar.gz’ had non-
> > zero exit status
> >
> >
> > Furthermore, I do get the same error from attempting to install
> > pkg:twine from github.
> >
> > -- David
> >
> > Doing this from an Rstudio console running R 3.5.1 in Ubuntu 18.04
> >
> > On 11/11/18 8:30 AM, Ferri Leberl wrote:
> > > Dear All,
> > > Thanks to Peter for his hint to the lwline package.
> > > As a pitty, I have difficulties to get it installed, as it requires
> > https://github.com/Gibbsdavidl/twine which failes for me.
> > >
> > > install_github("git using github.com:Gibbsdavidl/twine.git")
> > >
> > > ends with
> > >
> > > ** building package indices
> > > Error in read.table(zfile, header = TRUE, as.is = FALSE) :
> > >    more columns than column names
> > > ERROR: installing package indices failed
> > > * removing ‘/usr/local/lib/R/site-library/twine’
> > > Fehler in i.p(...) :
> > >    (konvertiert von Warnung) installation of package
> > > ‘/tmp/RtmpD3exKe/file730c303b4c3/twine_0.1.tar.gz’ had non-zero exit
> > > status
> > >
> > > I found hints like
> > > https://community.rstudio.com/t/lazydata-failed-for-for-package/4196
> > > and https://stat.ethz.ch/pipermail/r-help/2011-March/272829.html
> > > that boil down to problems within the data subdir of the project –
> > > but
> > I cannot (and should not) edit the project, can I?
> > >
> > > Can anybody help me solving the problem?
> > > Thank you in advance!
> > > Yours, Ferri
> > >
> > >
> > >
> > > Gesendet: Sonntag, 11. November 2018 um 15:38 Uhr
> > > Von: "Peter Dalgaard" <pdalgd using gmail.com>
> > > An: "Ferri Leberl" <ferri.leberl using gmx.at>
> > > Cc: r-help using r-project.org
> > > Betreff: Re: [R] Line with linearly changing thickness Hmm... I
> > > don't recall whether this has been packaged up, but Paul Murrell
> > > talked
> > about it at useR in Brisbane.
> > >
> > > https://www.youtube.com/watch?v=L6FawdEA3W0
> > >
> > > -pd
> > >
> > >> On 11 Nov 2018, at 11:44 , Ferri Leberl <ferri.leberl using gmx.at> wrote:
> > >>
> > >>
> > >> Dear All,
> > >> I want to depict flows: At point x there is an input of a units. at
> > point y, b units arrive.
> > >> Obviously, the line thicknes can be manipulated with (a constant)
> > cex. But I want the thickness to change linearly from ~a in x to ~b in
> > y.
> > >> Is there an out of the box solution for this?
> > >> Thank you in advance!
> > >> Yours, Ferri
> > >>
> > >> ______________________________________________
> > >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > >> https://stat.ethz.ch/mailman/listinfo/r-help[https://stat.ethz.ch/m
> > >> ai lman/listinfo/r-help] PLEASE do read the posting guide
> > >> http://www.R-project.org/posting-guide.html[http://www.R-project.or
> > >> g/ posting-guide.html] and provide commented, minimal,
> > >> self-contained, reproducible code.
> > > --
> > > Peter Dalgaard, Professor,
> > > Center for Statistics, Copenhagen Business School Solbjerg Plads 3,
> > > 2000 Frederiksberg, Denmark
> > > Phone: (+45)38153501
> > > Office: A 4.23
> > > Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > ______________________________________________
> > > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html and provide commented, minimal, self-contained,
> > reproducible code.
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list