[R] adding year information to a scatter plot

Rubén Roa rroa at azti.es
Mon May 3 08:17:56 CEST 2010


> -----Mensaje original-----
> De: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] En nombre de Ozan Bakis
> Enviado el: domingo, 02 de mayo de 2010 21:25
> Para: r-help at r-project.org
> Asunto: [R] adding year information to a scatter plot
> 
> Hi R users,
> 
> I would like to add year information to each point in a 
> scatter plot. The following example shows what i mean:
> 
> df=data.frame(year=c(2001,2002,2003),a=c(8,9,7),b=c(100,90,95))
> df
> plot(b~a,data=df)
> 
> Now, I would like to see which point belongs to 2001, 2002 
> and 2003 in the above graphic.
> 
> Thank you very much,
> ozan

Use text,
df <- data.frame(year=c(2001,2002,2003),a=c(8,9,7),b=c(100,90,95))
df
plot(b~a,data=df,ylim=c(.98*min(b),1.02*max(b)))
text(x=df$a,y=df$b-.01*max(df$b),lab=format(df$year))

____________________________________________________________________________________ 

Dr. Rubén Roa-Ureta
AZTI - Tecnalia / Marine Research Unit
Txatxarramendi Ugartea z/g
48395 Sukarrieta (Bizkaia)
SPAIN



More information about the R-help mailing list