On Thu, 19 Dec 2002, Saurav Pathak wrote:
> i have just begun using R, so please bear with me.
>
> i am trying to use cmdscale and display the result. i read the data
> using read.table(), calculate the proximity matrix using dist() and
> the display the result using the cmdscale(). this is very fine.
>
> in addition, i want the display to distinguish between two classes
> of records in my data. i have my data records marked as "1" or
"0".
> so i want to display 1's and 0's. how may i do that?
There are examples of this in library/MASS/scripts/ch11.R, and see below
>
> i use the following code:
>
> ----
> > fj <- read.table("fj")
> > names(fj)
> [1] "V1" "V2" "V3" "V4"
"V5" # "V5" contains the class mark (1 or 0)
> > #
> > # since i dont want the class attribute in the distance matrix
> > # i create another data.frame dropping it. but how do i pass it
> > # so that I may use it while plotting?
> > fjN <- data.frame(V1=fj$V1, V2=fj$V2, V3=fj$V3, V4=fj$V4)
> > library(mva)
> > fjNDist <- dist(fjN, method="euclidean")
Just fj[,-5] will do here
> > fjCMDS <- cmdscale(fjNDist)
> > plot(x, y, type="n", main="cmdscale(fjNDist)")
> > text(x, y, ".", cex=0.8)
Don't use text to plot a dot, use points().
text(x, y, labels=fj$V5)
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595