[R] Organising tick-marks in plot()
S Ellison
S.Ellison at lgc.co.uk
Fri Nov 30 13:47:45 CET 2007
Ted,
I don't think you can include the axis ticks in plot(), but you can
specify them in axis() using
plot(x,y,xlim=c(0,1000), axes=F)
box()
axis(1,at=seq(0,1000,50),labels=F)
axis(1,at=seq(0,1000,200),labels=T)
Obviously, if you want this to be variable for different xlim etc, your
simplest answer is to write an enhanced axis function. For example
Axis<-function(side,at,skip=4,...) {
axis(side,at=at, labels=F,...)
axis(side,at=at[ ( (1:length(at) %% skip ) == 1 )] , labels=T,
tick=F)
}
#labels every skip'th tick
Then
plot(x,y,axes=F)
Axis(1,at=seq(0,1000,50), skip=4)
If you want the tick marks at default values and to intersperse extra
ticks, axis() returns tick mark locations from which you can deduce the
labelled tick interval and then calculate an interval for intermediate
ticks in a second call with labels=F, eg
at.labels=axis(1)
axis(1,at=seq(at.labels[1], at.labels[length(at.labels)],
(at.labels[2]-at.labels[1])/4), labels=F )
... and again, you can wrap that in a funtion if you want.
At worst, they can just paste the function onto the command line
without understanding it.
BUT that is obviously not a good way to learn how to use R. I
personally don't think there's much point in pretending either R or
statistics can be used without a good deal of understanding, and that
it's better to bite the bullet and take the time to learn to use both
properly. If there isn't the time, either it wasn't that important to
add interspersed tick-marks or R is the wrong package - they should
really buy SigmaPlot or something with more point-and-click controls.
Steve Ellison
>>> Ted Harding <Ted.Harding at manchester.ac.uk> 30/11/2007 11:55:20 >>>
Hi Folks,
I'm advising someone who's a beginner with R,
and therefore wants the simplest answer possible.
The issue is to produce a plot using
plot(x,y,...)
where, on the X-axis, the tick-marks should be
on the lines of:
-- Range of X-axis: 0:1000
-- tick-marks labelled "0","200",...,"800","1000"
-- unlabelled tick-marks every 50 from 0 to 1000.
regardless of the actual range of x-values (which
however would normally range over most of 0:1000).
I've looked at the Q-Q Plot example in the MASS
book (Section 3.4), which does achieve this kind
of effect, but the code is too complicated for
the present context. (Whatever code is used needs
to be readily changeable for different plots of
the same general kind).
Is there a way of supplying straightforward
arguments to plot() which would achieve this?
I've been reading and site-searching for a while,
and the best I can find is on the lines of
plot((x,y,pch="+",col="blue",xlim=c(0,1000),xaxt="n")
par(xaxp=c(0, 1000, 50))
axis(1)
which is already complicated enough in the present
context; but it doesn't do exactly what is required
since (for example) if the x-values range from
0 to 900 the labelled tick-marks are at
0 60 140 220 300 380 460 540 620 700 780 860 940
and have therefore been computed from the range of
the data, and not from the specified range of the x-axis.
Help please!
Best wishes to all,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 30-Nov-07 Time: 11:55:16
------------------------------ XFMail ------------------------------
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list