[R] histogram y-scaling

Randy Zelick zelickr at pdx.edu
Mon Apr 19 16:00:48 CEST 2004

Hello all,

Relative to WinXP & R1.8....

I have two histograms to plot, and for comparison purposes I want them to
have the same Y-scaling. I tried to find the size of the bin with the
maximum count before generating the histogram, but this did not work (see
below). What is a better way?

par(mfrow=c(2,1)) # set up for plotting in 2 rows and 1 column

x1<-seq(-0.5,58.5,1) # make a range of x values for histogram

I thought the following lines would allow me to capture the results of the
hist function and determine the max bin count for scaling *before* making
the plot, but R cleverly saw around my method and plots it anyway. With
this code I get two plots.

q=hist(mt1,x1)       # stick results in a variable... alas also plots
cts=q$counts         # get the bin counts
mct1=max(cts)        # how many values in the bin with the most values
hist(mt1,x1)         # generate histogram plot

# go on with histogram #2...



R. Zelick				email: zelickr at pdx.edu
Department of Biology			voice: 503-725-3086
Portland State University		fax:   503-725-3888

P.O. Box 751
Portland, OR 97207

1719 SW 10th Ave, Room 246
Portland, OR 97201

More information about the R-help mailing list