RE: [R] "text"-function: adding text in an x,y-plot

From: John Fox <jfox_at_mcmaster.ca>
Date: Mon 30 May 2005 - 02:15:57 EST


Dear Helmut,

The problem is that you're implicitly coercing the entire data frame lab to character, producing

> as.character(lab)

[1] "c(1, 3, 4, 5, 6, 7, 8, 9, 10, 2)"

The numbers themselves come from the numeric coding of the factor V1 in this data frame; as.numeric(lab$V1) shows you what's going on.

Instead you could specify labels=lab$V1 in the text() command. But why put the row names in a data frame in the first place; why not simply use labels=rownames(out.pca)?

I hope this helps,
 John



John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Helmut
> Kudrnovsky
> Sent: Sunday, May 29, 2005 11:08 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] "text"-function: adding text in an x,y-plot
>
> Hello R-friends,
>
> i have a question to the "text"-function.
>
> a little test-dataset for better understanding:
>
> -the dataset was imported with read.table(....,header=TRUE)
> s1-s10 are the samplenames
>
> var1 var2 var3
> s1 1 1 2
> s2 2 3 1
> s3 2 2 3
> s4 5 4 3
> s5 4 2 3
> s6 6 3 2
> s7 8 5 4
> s8 7 2 1
> s9 9 3 2
> s10 8 6 4
>
> -then ive performed a pincipal component analysis with prcomp
>
> -for displaying the result in a x,y-graph i transformed
> out.pca$x into the dataframe points
> points <- out.pca$x
> > points
> PC1 PC2 PC3
> s1 -4.7055777 -0.14781544 -0.3683602
> s2 -3.1854599 0.19661476 1.5212455
> s3 -3.2687980 0.78193513 -0.6352458
> s4 0.2278948 1.00061498 0.2164108
> s5 -1.4382847 0.02500633 -0.9114340
> s6 0.6216283 -0.68606440 0.2071083
> s7 3.4951878 1.17343675 -0.3266629
> s8 1.0153619 -2.37274378 0.1978058
> s9 3.3673983 -1.82145761 -0.2071739
> s10 3.8706492 1.85047328 0.3063065
>
> - with plot(points$PC1, points$PC2, type="n") i start a graph
> without displaying anything at the x,y-coordinates
>
> - i want now to display the samplenames at the right
> x,y-coordinate; i generated a dataframe called lab with the
> samplenames
>
> > lab
> V1
> 1 s1
> 2 s2
> 3 s3
> 4 s4
> 5 s5
> 6 s6
> 7 s7
> 8 s8
> 9 s9
> 10 s10
>
> - ive studied the "text"-helppage and so i tried the following:
>
> text(pca$PC1, pca$PC2, labels=lab)
>
> - in the plot there is now c(1,3,4,5,6,7,8,9,10,2) displayed
> instead of s1-s10
>
> is out there any idea what i'am doing wrong? is there maybe
> another way of displaying the samplenames at the right x,y-coordinate?
>
> greetings from the sunny tirol with thanks in advance helli
>
> platform i386-pc-mingw32
> arch i386
> os mingw32 - win xp
> system i386, mingw32
> status
> major 2
> minor 1.0
> year 2005
> month 04
> day 18
> language R
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon May 30 02:25:33 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:15 EST