s-news
[Top] [All Lists]

Summary: control of axis plotting

To: "S_question (E-mail)" <s-news@lists.biostat.wustl.edu>
Subject: Summary: control of axis plotting
From: "Prins, N.H. (Klaas)" <klaas.prins@organon.com>
Date: Fri, 14 Jun 2002 11:29:51 +0200
Below a summary of the answers on the control of axis plotting, including my
interpretation.
Thanks for the answers provided by Jim Pratt, Jean Adams and Bert Gunter.
The "my.axis" function was provided Gerald Jean, who got it from Bill Dunlap
from Insightful.

1. Appearance of decimals in the labels will occur for example when
labels=c(0.01,0.1,1,10,100), then even 100 is labelled in the plot as 100.00
to get around this, use either 

round(x,2)
 
axis(2,c(0.01,0.1,1,10,100,1000),labels=(text=round(c(0.01,0.1,1,10,100,1000
),0)))

or as.character()
 
axis(2,c(0.01,0.1,1,10,100,1000),labels=(text=as.character(c(0.01,0.1,1,10,1
00,1000))))

or similarly,....text=c("0.01","0.1","1","10","100","1000")

or let S+ calculate to most efficient abbreviation using abbreviate()
 
axis(2,c(0.01,0.1,1,10,100,1000),labels=(text=abbreviate(c(0.01,0.1,1,10,100
,1000),minlength=8)))



2. Getting positioning of labels, lines and texts right:

"my.axis" <- function(side, at, labels, ...)
{
  for(i in seq(along=at))
    axis(side=side, at=at[i], labels=labels[i], ...)
}

ylabel<-c(0.01,0.1,1,10,100,1000)
my.axis (side = 1, at = ylabel,
         labels = abbreviate(ylabel, minlength = 8),   # abbreviate is a
builtin function.
         crt = 45,                                     # rotate labels 45
degrees.
         col = 1,                                      # color of tick
labels, black here.
         adj = 0.5,                                    # position of labels
in the available space,
                                                       #  in the middle
here.
         cex = 1.0,                                    # character expansion
relative to current font.
         mgp = c(3.0,2.5,0))                           # margin line for the
axis title, axis labels,
                                                       # and axis line in
units of mex.
                                                       # The default is
c(3,1,0).

!!!!! Unfortunately, this function does not plot an axis line!!!!!!!!!
use either box(n=1) or axis.line.render(side=2) to create an axis line.

Positioning could also be fiddled with the parameters in par(), which are
mar(xbottom,xleft,xtop,xright) and mgp(title,labels,line), see ?par for
details.
Jim Pratt's suggestion:

par(mar=c(5,6,4,2)+.1)#adds 2 lines of space to y-axis, side=2
plot(plot(x,y,log="y",type="l",axes=F)
axis(1,x,labels=(text=x))
axis(2,c(1,10,100,1000),labels=(text=c("1","10","100","1000")),mgp=c(5,1,0),
adj=1)

(adj= takes care of string justification, see ?par)

Kind regards,
Klaas



--------------------------------------------------------------------
This message, including attached files, may contain confidential
information and is intended only for the use by the individual
and/or the entity to which it is addressed. Any unauthorized use,
dissemination of, or copying of the information contained herein is
not allowed and may lead to irreparable harm and damage for which
you may be held liable. If you receive this message in error or if
it is intended for someone else please notify the sender by
returning this e-mail immediately and delete the message.
--------------------------------------------------------------------


<Prev in Thread] Current Thread [Next in Thread>
  • Summary: control of axis plotting, Prins, N.H. (Klaas) <=