[R] plotting
Marc Schwartz
MSchwartz at MedAnalytics.com
Thu Mar 10 01:52:14 CET 2005
On Wed, 2005-03-09 at 14:28 -0400, Owen Buchner wrote:
> I have two questions for you. Firstly I'm having troubles trying to plot more
> then 1 graph. I'm attempting to make a plot with 9 panels, but i have no clue
> what type of code to use.
If you are using R's base graphics and you want 9 plots arranged
vertically, you can use par(mfrow = 9) before your first plot.
The first plot will then be in the top panel (row).
Each successive call to a high level plot function [ie. plot(), boxplot
(), barplot()] will draw the plot in the next panel (row) down.
See ?par for more information and some examples.
Another option, for base graphics, is to use the layout() function and
yet another, is to use the grid/lattice packages for creating "Trellis"
type plots.
> Secondly i was wondering if there was some code to generate random numbers
> between two defined intervals and then have R chose one randomly in a program.
> If you could answer either of these questions for me I would appreciate it.
If you want to generate random numbers from a pre-specified sequence of
numbers between some min and max values (each number having an equal
probability of being selected) and then return one of them, you can use
the sample function:
sample(min:max, 1)
See ?sample for more information. Note that the sequence need not be all
integers:
> sample(seq(1, 10, 0.5), 1)
[1] 2.5
If you want the random numbers to be within some min:max set of limits,
such that:
min <= x <= max
each 'x' having an equal probability of being selected and then return
one of the numbers, use runif():
runif(1, min, max)
See ?runif for more information.
HTH,
Marc Schwartz
More information about the R-help
mailing list