[R] How do I order xyplot line points?
Alex Reynolds
reynolda at u.washington.edu
Sun Nov 7 13:17:21 CET 2010
I have the following xyplot figure:
http://img577.imageshack.us/img577/686/filesizeresults12000000.png
The data are organized in a matrix file as follows:
Type Elements Chromosome Time
bedGz 12000000 chr1 14.240
bedGz 12000000 chr2 7.949
bedGz 12000000 chr3 5.103
bedGz 12000000 chr4 5.290
bedGz 12000000 chr5 5.161
...
The x-axis labels in the Chromosome column are ordered lexicographically in my figure ( chr1 > chr10 > chr11 > ... ) — this is correct.
However, the code I use to draw lines between points in the xyplot connects points in numerical order ( chr1 > chr2 > ... ) — this is incorrect.
The problem this causes is most evident in the line that is drawn for the blue "bedGz" category.
What I would like is that categorical points are joined by lines in lexicographic order, to match ordering of labels on the x-axis.
How do I modify the xyplot command so that the lines are joined in correct order?
Here is the code I am using to draw my xyplot:
mtx <- read.table(mtxf.in, as.is=F, sep="\t", quote='', header=T, stringsAsFactors=T)
attach(mtx)
postscript(mtxf.ps,
width = 12,
height = 6,
paper = 'special',
horizontal = F)
par(mar=c(0.0, 0.0, 0.0, 0.0))
mtx.p <- xyplot(Time~Chromosome|factor(Elements),
mtx,
type="o",
groups=Type,
col = c(
'red',
'green',
'red',
'green',
'blue'),
auto.key=list(
lines=TRUE,
space="right"),
ylab="CPU Time (sec)",
xlab="Type",
main="Extraction time for archive types")
print(mtx.p)
dev.off()
Sorry if this is a dumb question. Thanks for your advice.
Regards,
Alex
More information about the R-help
mailing list