[R] controlling usage of digits & scientific notation in R plots; postscript margins
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Sep 22 09:33:04 CEST 2005
Concise answers to verbose questions:
1) Use options(scipen) (and probably change the margin sizes).
Or something like
options(scipen=10)
par(mar=c(5,8,4,2)+0.1)
plot(x, y, axes=FALSE)
axis(2, las=2)
axis(1, labels=FALSE)
axis(1, at = c(-2e8, 2e8), labels = expression(-2 %*% 10^8, 2 %*% 10^8))
2) This is a function of the including application, in particular the
macro package used in latex. Some use the bounding box (rather than the
paper size) for files marked with EPSF in the header, which is done if
onefile=FALSE (sic). For others you need paper="special" as well.
Hence the advice in ?postscript. Just follow it!
On Wed, 21 Sep 2005, Paul Johnson wrote:
> Dear R users:
>
> I assigned students to make some graphs and I'm having trouble answering
> some questions that they have. We are all working on R 2.1 on Fedora
> Core Linux 4 systems.
There is no `R 2.1': please do study the posting guide.
> 1. In the plot, the axis is not labeled by "numbers", but rather
> scientific notation like "-2e+08" or such. We realize that means
> -200,000,000. We want to beautify the plot. We would rather just print
> out the whole, big number. But if we can't have that, we would like
> something more beautiful and mathematical, such as
> 8
> -2.0x10
>
> Once the numbers are big, R automagically switches to scientific
> notation, and turning the values horizontal does not help on the y axis.
>
> Example:
>
> x <- rnorm(100,mean=100000,sd=100000000)
> y <- rnorm(100,mean=10000000000,sd=100000000000)
> plot(x,y,axes=F)
> axis(2,las=2) #turns y axis numbers perpendicular to y axis
> axis(1) # x axis
>
> I realize a person could just divide all numbers by 1 million and then
> have a graph with -200 and an annotation (in millions).
>
> On the x axis, we'd even settle to just label the two outermost points
> with full numerical values, and then have only ticks between. I was
> looking for some way to use axis() to draw an unlabeled axis and then
> put in text labels after that. However, I can't understand how to get
> the values of the tick marks placed by axis from the figure in order to
> place text by some tick marks.
>
> 2. Some students make postscript figures that fit "just right" into
> LaTeX documents, while some make figures that have huge,
> inches-and-inches of margins around the outside. I'm not watching how
> they make these figures all the time, but I think I'm figuring out the
> cause of big margins.
>
> Is this right: the margins issue relates to the use of the onefile=F
> option in a dev.copy command? I think the figures turn out properly
> with this:
>
> dev.copy(postscript,file="myfig.eps",height=5,width=5,horizontal=F,onefile=F)
> dev.off()
>
> If you mistakenly omit the onefile=F option, the margins stretch out
> from the center where the figure is placed to the edges of an entire
> sheet of paper. In other words, the default settings for margins in
> inches that I see in output from
>
> > par()
> ...
> $mai
> [1] 1.0066821 0.8092935 0.8092935 0.4145162
> ...
>
> have no effect if a person forgets the onefile=F option. We fiddled a
> while, trying to force margins down, par(mai=c(0,0,0,0)), but no matter
> what we did, the figures still had the massive margins.
>
> We don't have these margin problems with other devices. Margins in jpeg
> or png pictures are sized appropriately.
>
>
> --
> Paul E. Johnson email: pauljohn at ku.edu
> Dept. of Political Science http://lark.cc.ku.edu/~pauljohn
> 1541 Lilac Lane, Rm 504
> University of Kansas Office: (785) 864-9086
> Lawrence, Kansas 66044-3177 FAX: (785) 864-5700
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list