[R] Transform distance constraints into a 2D-map

Emmanuel Levy emmanuel.levy at gmail.com
Thu Apr 5 17:37:06 CEST 2007


Dear All,

Thank you for your replies. That will definitly get me started.

Ted: I said optimize because I suppose that an exact solution does
not necessarily exists sometimes.

Best,

Emmanuel



On 4/5/07, Ted Harding <ted.harding at nessie.mcc.ac.uk> wrote:
> On 05-Apr-07 13:05:29, Emmanuel Levy wrote:
> > Dear all,
> >
> > Could you please point me out to a function or set of functions
> > that would allow me to optimize positions on the 2D map of points
> > for which I are distance contrainted?
> >
> > for example, if I have:
> >     a   b   c
> > a 0.0 0.5 0.7
> > b 0.5 0.0 0.3
> > c 0.7 0.3 0.0
> >
> > I would like to obtain (x,y) coordinates to plot A,B,C so that the
> > distance constraints are satisfied. i.e. a is 0.5 far from b, and o.7
> > far from c. etc ...
> >
> > Many thanks for your help,
> >
> > Best,
> >
> > Emmanuel
>
> Probably any of the multidimensional scaling functions variously
> available would do (it is not clear what you mean by "optimize",
> though). In your example above, an exact solution exists.
>
> For example
>
> library(MASS)
> D<-matrix(c(0.0, 0.5, 0.7, 0.5, 0.0, 0.3, 0.7, 0.3, 0.0),nrow=3)
> rownames(D)<-c("a","b","c")
> colnames(D)<-c("a","b","c")
>
> P<-isoMDS(D)$points
> plot(P[,1],P[,2],pch="+",col="blue")
>
> P
> ##          [,1]        [,2]
> ## a  0.39114338  0.03809598
> ## b -0.08358748 -0.11884547
> ## c -0.30755590  0.08074949
>
> dist(P)
> ##      a   b
> ## b  0.5
> ## c  0.7 0.3
>
> The last result shows that the distances betweem the three points
> in the 3 rows of P are as desired: a<->b=0.5, a<->c=0.7, b<->c=0.3
>
> Hoping this helps!
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 05-Apr-07                                       Time: 16:29:49
> ------------------------------ XFMail ------------------------------
>



More information about the R-help mailing list