It is not hard to create a basic function for that purpose:
map.vec <- function(x, y) {
dfa <- data.frame(a=x, x0=rep(1, length(x)),
y0=length(x):1)
dfamap <- data.frame(a=y, x1=rep(2, length(y)),
y1=length(y):1)
vec <- merge(dfa, dfamap, by=1)
plot(c(0, 3), c(0, length(x)+1), xlab="", ylab="",
type="n", axes=FALSE)
text(1, length(x):1, as.character(x))
text(2, length(y):1, as.character(y))
arrows(vec[,2]+.05, vec[,3], vec[,4]-.05, vec[,5],
length=.15)
}
a <- c(2, 8, 5)
a.mapped <- c(8, 2, 5)
set.seed(42)
b <- sample.int(15, 10)
b.mapped <- sample(b)
map.vec(a, a.mapped)
map.vec(b, b.mapped)
-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Jie
Sent: Thursday, August 22, 2013 1:33 PM
To: r-help
Subject: [R] graph related question
Dear All,
I would like to draw a graph to illustrate the mapping between
two vectors.
For instance,
a = c(2, 8, 5) ; mapped.a = c(8, 2, 5)
I would like to get some picture as
http://www.flickr.com/photos/96546690 at N02/9569526581/
Basically, plot all points of a in a vertical line, and mapped.a
in
another vertical line, finally link the same element by a arrow.
Thank you for any advice.
Best wishes
Jie
______________________________________________
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.