[R] Margin annotation

David Winsemius dwinsemius at comcast.net
Mon Oct 22 23:01:28 CEST 2012


On Oct 22, 2012, at 1:51 AM, PIKAL Petr wrote:

> Hi
> 
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of David Arnold
>> Sent: Monday, October 22, 2012 4:26 AM
>> To: r-help at r-project.org
>> Subject: [R] Margin annotation
>> 
>> I have this code:
>> 
>> x=seq(80-3*15,80+3*15,length=200);
>> y=dnorm(x,80,15)
>> plot(x,y,type="l",lwd=2,col="red")
>> x=seq(80-3*15,70,length=100)
>> y=dnorm(x,80,15)
>> polygon(c(0,x,70),c(0,y,0),col="gray")
>> text(70,0.005,"70")
>> 
>> I'd like to draw the number "70" in red underneath a vertical arrow
>> pointing to the position of the number 70 on the horizontal axis.
>> 
>> Any ideas?
> 
> I am not exactly sure what do you want. 
> 
> text(70,0.005,"70", col="red")
> 
> put a number 70 in red.

And the OP may also need the 'xpd' parameter (which `text` and `arrows` will accept) if it is desired to put the text outside the plot area as the subline suggests might be the case.

> text( 70, -0.004,"70", col="red", xpd=TRUE)  # note use of usr-coordinates even outside plot area
> arrows(x0=70, y0=-.003, x1 = 70, y1 = 0, col="red", xpd=TRUE, length=0.1, lwd=3)
> 
OR perhaps:

> text(70,-0.004,"70", col="red",xpd=TRUE)
> arrows(x0=70, y0=-.003, x1 = 70, y1 = 0.0045, col="red", xpd=TRUE, length=0.1, lwd=3)
> 
-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list