[R] dist label names

Jari Oksanen jari.oksanen at oulu.fi
Thu Apr 26 09:52:40 CEST 2007

 <L.Stirton <at> uea.ac.uk> writes:

> Hello,
> I am trying to do a multi-dimensional scaling of the World Bank's quality
> of governance indicators for the Balkan region. I am having trouble
> labelling my plot. Could some kind person help me out. How do I set the
> attribute Label by a variable (say, "Code")? At present I get this:
> >qog.dist<-dist(Balkans.data, method = "euclidean", diag = FALSE, upper =
> labels(qog.dist)
>  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"
> I know this must be a really basic questions, but none of the 5-6 books on
> my shelf nor a web search have proved much help. In case you hadn't
> guessed, I am pretty new to R.

Not very much detail here, but I assume you use isoMDS (MASS package), and you
have reasonably current version of MASS and R. Further, I assume your data.frame
(Balkans.data) has row names, and thes row names are saved as dist labels. If
any of these is not true, correct the situation (install new MASS or VR bundle,
give rownames to your data frame -- there was a brief period when the names were
not correctly transferred from dist to isoMDS). 

If the problem was to label your dist result, you can do it like this

rownames(Balkans.data) <- typenamesorgiveavariablenamecontainingnames

and now dist will be labelled correctly, and the names are transferred to isoMDS

Now your isoMDS result should have the labels as rownames to points. Then you
can do something:

mod <- isoMDS(gog.dist)
plot(mod$points, asp=1, type="n")
text(mod$points, rownames(mod$points))

I hope this helps. However, it is new to me that Euclidean distance is an
appropritae metric for governance indicators (but none of my business).

Cheers, jari oksanen

More information about the R-help mailing list