Hi is there a automatic way that long distances between points are not connected. I have something like plot(x,y,type="o",...) atx <- seq(as.Date("2009-04-01"),as.Date("2011-04-01"),"month") axis.Date(1, at=atx,labels=format(atx, "%b\n%Y"), padj=0.5 ) but I do not want lines between points whose distance is greater than two weeks. thx Christof
Hi> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Christof Klu? > Sent: Friday, October 26, 2012 1:42 PM > To: r-help at stat.math.ethz.ch > Subject: [R] connect points in charts > > Hi > > is there a automatic way that long distances between points are not > connected. I have something like > > plot(x,y,type="o",...) > > atx <- seq(as.Date("2009-04-01"),as.Date("2011-04-01"),"month") > > axis.Date(1, at=atx,labels=format(atx, "%b\n%Y"), padj=0.5 ) > > but I do not want lines between points whose distance is greater than > two weeks.You can discard a line by entering NA between dates. plot(1:10, 1:10, type="o") plot(c(1:5,NA,7:10), 1:10, type="o") So you shall construct new data in which you put NA on propper places. Regards Petr> > thx > Christof > > ______________________________________________ > R-help at r-project.org mailing list > 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.
Christof, You could use single linkage clustering to separate the dates into different groups if they are more than 14 days apart. Below is a simple example, where x represents day. x <- sort(sample(1:500, 100)) y <- rnorm(100) cluster <- hclust(dist(x), method="single") group <- cutree(cluster, h=14) plot(x, y, col=group) for(i in unique(group)) lines(x[group==i], y[group==i], col=i) Jean Christof Kluß <ckluss@email.uni-kiel.de> wrote on 10/26/2012 06:41:54 AM:> > Hi > > is there a automatic way that long distances between points are not > connected. I have something like > > plot(x,y,type="o",...) > > atx <- seq(as.Date("2009-04-01"),as.Date("2011-04-01"),"month") > > axis.Date(1, at=atx,labels=format(atx, "%b\n%Y"), padj=0.5 ) > > but I do not want lines between points whose distance is greater than > two weeks. > > thx > Christof[[alternative HTML version deleted]]