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 [[alternative HTML version deleted]]
I think that one of the packages, perhaps Hmisc or plotrix does this but you can also do it just using text() Example plot(b~a,data=df, xlim=c(min(df$a)-5,max(df$a)+5), ylim= c(min(df$b)-5,max(df$b)+5)) text( df$a+1,df$b, labels=df$year) Alternatively you can do this in ggplot library(ggplot) p <- ggplot(df, aes(x=a, y=b, label=year)) p + geom_text() --- On Sun, 5/2/10, Ozan Bakis <obakis at gsu-giam.net> wrote:> From: Ozan Bakis <obakis at gsu-giam.net> > Subject: [R] adding year information to a scatter plot > To: r-help at r-project.org > Received: Sunday, May 2, 2010, 3:25 PM > 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 > > ??? [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org > mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. >
Hi Ozan, The {calibrate} package allows you to do that. install.packages("calibrate") library(calibrate) df=data.frame(year=c(2001,2002,2003),a=c(8,9,7),b=c(100,90,95)) df plot(b~a,data=df) textxy(df$a,df$b,df$year) Muhammad On 05/02/2010 08:25 PM, Ozan Bakis wrote:> 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 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
> -----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, > ozanUse 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
Maybe Matching Threads
- conditional grouping of variables: ave or tapply or by or???
- conditional weighted quintiles
- Identifying a subset of observations on a 3d-scatter plot using cloud()
- Need help in calculating studentized residuals/leverage values of non-linear model [nls()]
- compiling kernel in Centos Domu