[R] controlling usage of digits & scientific notation in R plots; postscript margins

Greg Snow greg.snow at ihc.com
Thu Sep 22 00:08:59 CEST 2005

One option is to use the 'scipen' option.  see ?options and look for

An example:  

# now do your plot and see what happens (try bigger numbers if 3
doesn't change anything).

you can also specify different axis locations and labels to do it by

plot( (1:10)*1e+5, 1:10, xaxt='n')
axis(1, at=(1:10)*1e+5, labels=paste( 1:10, "*10^5", sep=''))

also look at ?plotmath if you want actual superscripts.

Hope this helps,

Greg Snow, Ph.D.
Statistical Data Center, LDS Hospital
Intermountain Health Care
greg.snow at ihc.com
(801) 408-8111

>>> Paul Johnson <pauljohn at ku.edu> 09/21/05 03:42PM >>>
Dear R users:

I assigned students to make some graphs and I'm having trouble
some questions that they have.  We are all working on R 2.1 on Fedora 
Core Linux 4 systems.

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

Once the numbers are big, R automagically switches to scientific 
notation, and turning the values horizontal does not help on the y


x <- rnorm(100,mean=100000,sd=100000000)
y <- rnorm(100,mean=10000000000,sd=100000000000)
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:


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()
[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
PLEASE do read the posting guide!

More information about the R-help mailing list