Benjamin Tyner
2006-Sep-16 20:28 UTC
[R] dotplot/Dotplot: connecting points within factor level across time
For each level of the factor in dotplot, I have time points I'd like to
connect with a line. In the example below, 'x' represents a starting
time and 'd' a duration, and I wish to connect 'x' to
'x+d'. Ordinarily
I would use Dotplot from hmisc for this, but I have not been able to
find a time class that Dotplot will allow. I can get lattice dotplot to
put the points up, but I've not figured out how to connect them. Any
suggestions?
require(lattice)
z<-data.frame(y=factor(letters),
x=structure(1:26,class=c("POSIXt","POSIXct"),tzone=""),
d=runif(26))
# this puts the points, but does not connect them
p<-dotplot(y~x+I(x+d),
data=z,
scales=list(x=list(format="%M:%S"))
)
zh<-z
zh$x<-as.numeric(zh$x)
require(hmisc)
# this connects them, but at the expense of the time info
ph<-Dotplot(y~Cbind(x,x,x+d),
data=zh,
pch=" ")
Thanks,
Ben
Gabor Grothendieck
2006-Sep-17 00:55 UTC
[R] dotplot/Dotplot: connecting points within factor level across time
Try this:
print(p)
trellis.focus("panel", 1, 1)
with(z, panel.segments(x, as.numeric(y), x+d, as.numeric(y)))
trellis.unfocus()
On 9/16/06, Benjamin Tyner <btyner at gmail.com>
wrote:> For each level of the factor in dotplot, I have time points I'd like to
> connect with a line. In the example below, 'x' represents a
starting
> time and 'd' a duration, and I wish to connect 'x' to
'x+d'. Ordinarily
> I would use Dotplot from hmisc for this, but I have not been able to
> find a time class that Dotplot will allow. I can get lattice dotplot to
> put the points up, but I've not figured out how to connect them. Any
> suggestions?
>
> require(lattice)
> z<-data.frame(y=factor(letters),
>
x=structure(1:26,class=c("POSIXt","POSIXct"),tzone=""),
> d=runif(26))
>
> # this puts the points, but does not connect them
> p<-dotplot(y~x+I(x+d),
> data=z,
> scales=list(x=list(format="%M:%S"))
> )
>
> zh<-z
> zh$x<-as.numeric(zh$x)
> require(hmisc)
> # this connects them, but at the expense of the time info
> ph<-Dotplot(y~Cbind(x,x,x+d),
> data=zh,
> pch=" ")
>
>
>
> Thanks,
> Ben
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
Deepayan Sarkar
2006-Sep-18 23:23 UTC
[R] dotplot/Dotplot: connecting points within factor level across time
On 9/16/06, Benjamin Tyner <btyner at gmail.com> wrote:> For each level of the factor in dotplot, I have time points I'd like to > connect with a line. In the example below, 'x' represents a starting > time and 'd' a duration, and I wish to connect 'x' to 'x+d'. Ordinarily > I would use Dotplot from hmisc for this, but I have not been able to > find a time class that Dotplot will allow. I can get lattice dotplot to > put the points up, but I've not figured out how to connect them. Any > suggestions? > > require(lattice) > z<-data.frame(y=factor(letters), > x=structure(1:26,class=c("POSIXt","POSIXct"),tzone=""), > d=runif(26)) > > # this puts the points, but does not connect them > p<-dotplot(y~x+I(x+d), > data=z, > scales=list(x=list(format="%M:%S")) > ) > > zh<-z > zh$x<-as.numeric(zh$x) > require(hmisc) > # this connects them, but at the expense of the time info > ph<-Dotplot(y~Cbind(x,x,x+d), > data=zh, > pch=" ")If you can install packages from source, you could try installing http://www.stat.wisc.edu/~deepayan/R/segplot_0.0-1.tar.gz after which you could try: -------------------- library(segplot) segplot(y ~ x + (x+d), z, scales=list(x=list(format="%M:%S"))) segplot(y ~ x + (x+d), z, draw.bands = FALSE, scales=list(x=list(format="%M:%S"))) --------------------- I have been meaning to submit this to CRAN for a while, I haven't because it's lacking a good example (I think I'll go ahead and submit it anyway). Deepayan