Skip to content

Adding text to a plot

3 messages · Patrick Hausmann, Jun Yan, Joerg Maeder

#
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.

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:
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'?

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
text(max(k[,1], max[k,2], labels=paste(a,b,sep="\n"), adj=c(1,1))

You may try pos too.
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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hello Patrick

you can use special chars inside your string. For a linefeed you need
'\n'
c <- paste(a,b,sep='\n')
text(90, max((k[,2])-0.51), c)

gruess

joerg
Patrick Hausmann wrote: