adding labels to x,y points

3 posts / 0 new
Last post
baumeist
Offline
Joined: 09/15/2011
adding labels to x,y points

Hi,
I am new to R.

I have a dataframe that I have assigned to the object “colon”.

> colon<-read.table("c:\\alon.txt",header=T,row.names=1)

attach(colon)
names(colon)

It (i.e. colon) consists of 62 different columns (samples) or sets of data.

Each of the 62 columns (titled norm1, norm2, norm3, etc) has 2000
different numbers (‘continuous’ values) within it.

I have also assigned a name for each of the 2000 rows of the dataframe with a prefix (i.e. g1 …. g2000).

> colon<-paste("g",c(1:nrow(colon)),sep="")

I have plotted the first 20 values from two of the columns(samples).

> x<-c(norm1[1:20])

> y<-c(norm2[1:20])

> plot(x,y,type='n',xlab='x norm1 sample',ylab='y norm2 sample',main='Norm1 vs Norm2 - 20
genes')

> points(x,y,pch=15,col='blue')

Now I wish to assign labels to each point (above each point (i.e. pos=3) in the plot with “g1 to g20 corresponding to each row but I am having trouble with this step.

I have tried:

> text(x,y, label = row.names(colon[1:20]))

but nothing happens.

Any suggestions?

Thanks in advance
MAB




ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the general ProgrammingR RSS feed by clicking here. To be notified when new R-based job listings are posted, click here.

bryan
Offline
Joined: 01/15/2009

Hi baumeist,

A couple of recommendations:

First, I would not use the attach command. It makes things a little more difficult in the long run than just using direct references to the variables (e.g., colon$norm1).

Second, when you do this

colon<-paste("g",c(1:nrow(colon)),sep="")

you're creating an object with the same name as your attached data object. That is potentially confusing and could cause problems. Better to create something with a different name.

However, I think your main problem is that you're using row.names() in the "labels = attribute" of the text() function when you don't need to. The "colon" object your creating is just a vector with no row.names attribute. Try dropping that and see if you get what you want.

baumeist
Offline
Joined: 09/15/2011

Thanks a lot, Bryan.

Mark

Login or register to post comments