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

From: Greg Snow <greg.snow_at_ihc.com>
Date: Thu 22 Sep 2005 - 08:08:59 EST


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

An example:

options(scipen=3)
# 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 hand:

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@ihc.com
(801) 408-8111

>>> Paul Johnson <pauljohn@ku.edu> 09/21/05 03:42PM >>> 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.

  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@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@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

______________________________________________
R-help@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
Received on Thu Sep 22 08:13:54 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 17:36:41 EST