[R] graph related question

David Winsemius dwinsemius at comcast.net
Fri Aug 23 02:13:51 CEST 2013


On Aug 22, 2013, at 4:17 PM, Jim Lemon wrote:

> On 08/23/2013 04:32 AM, Jie wrote:
>> 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@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
>> 
> Hi Jie,
> Try the bumpchart function in the plotrix package. This just connects the points with lines. If you have to have arrows connecting the points, it would not take a great deal of programming.

I think looking at (and working through) the help page for ?segments might provide an answer.

plot(NA, xlim=c(0,3), ylim=range(c(0,length(a)+1)) )
arrows(x0=1.05, x1=1.95,
        y0=4-seq_along(a) ,y1=4-seq_along(mapped.a)[order(a)], 
        col=c("red","green","orange"))
text(x=1, y=seq_along(a), labels=a )
text(x=2, y=seq_along(a), labels=mapped.a )

-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list