[R] Arrow heads at the end of axes
Marc Schwartz
MSchwartz at MedAnalytics.com
Thu Oct 21 14:35:34 CEST 2004
On Thu, 2004-10-21 at 07:12, Henrik Andersson wrote:
> I would like to have arrow heads at the end of my axes, since I am
> plotting variable where the absolute amount is irrelevant, there is not
> supposed to be numbers on the axes.
>
> An imperfect example:
> plot(rnorm(10),bty='l',xaxt='n',yaxt='n',ylab='',xlab='',type='l')
> abline(h=0)
>
> Like this but without, the xaxis and with arrrowheads
>
> More like this in fact,
> LaTeX Picture example:
>
> \setlength{\unitlength}{1.3cm}
> \begin{picture}(4.3,3.6)(-2.5,-0.25)
> \put(-2,1.8){\vector(1,0){4.4}}
> \put(2.5,1.7){$x$}
> \put(-2,0){\vector(0,1){3.2}}
> \put(-2,3.35){\makebox(0,0){$y$}}
> \end{picture}
You can do something like this:
plot(rnorm(10), axes = FALSE)
# Get the axis ranges
u <- par("usr")
# Use arrows() to draw the axis lines, adding the arrowheads
# Use the par("usr") values to specify the end points of the lines
# Setting 'xpd = TRUE' allows for the arrowhead to be drawn outside
# the plot region as required here
arrows(u[1], u[3], u[2], u[3], code = 2, xpd = TRUE)
arrows(u[1], u[3], u[1], u[4], code = 2, xpd = TRUE)
See ?arrows for additional options to define the arrows.
HTH,
Marc Schwartz
More information about the R-help
mailing list