[R] Adding text to a plot

Jun Yan jyan at stat.wisc.edu
Wed Jul 3 16:29:32 CEST 2002


> Dear R-users,
> 
> again two question...
> 
> # Question 1
> Adding two lines of text to a plot, I am using:
> 
> # ------------------------------- 
> plot(k[,1], k[,2], pch=16, 
>     ylim=range((min(k[,2])-0.2):(max(k[,2])+1)))     
> 
> a <- paste("Cor.:" ,cor(k[,2],k[,1]))
> b <- paste(nrow(k), "Countries")
> 
> text(90, max((k[,2])-0.51), a)
> text(90, max((k[,2])-0.83), b)
> # -------------------------------
> But the distance between the first and second line depends on the 
> scale of the y-axis.

text(max(k[,1], max[k,2], labels=paste(a,b,sep="\n"), adj=c(1,1))

You may try pos too.

> Is there a solution to put the lines in the upper right corner, 
> independent of the y-scale?
> 
> # Question 2 
> My data.frame looks like:
> > u
>       country     gdp50     w5073
> 1.AUS  AUS     77.15967   2.1708460
> 1.AUT  AUT     74.06830   1.8691745
> 1.BEL  BEL     77.87497   1.7547546
> 1.CAN  CAN     87.07300   1.3649655
> [...]
> 
> To add labels on points in a plot I call: 
> text(x=u[,2]+chw, y=u[,3], labels=levels(u[,1]), adj=0 )
> 
> How can I label only the datapoints for 'CAN' and 'AUS'?

You may extract only those levels you need and text it. However, You need
to be careful in this case. Your data happens to be sorted by country,
which makes it in the same order as the levels of the factor 
country. Another way to do this might be to use different symbols and give
a legend.

Jun


> 
> Thanks for any help
> Patrick
> -------------
> Patrick Hausmann
> Friedrich-Wilhelm Str. 37 - D-28199 Bremen
> Tel. +49 421 5980631 - Fax. +49 421 5980632
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list