| 53846 |
murrell |
1 |
% File src/library/grid/man/grid.function.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2007 R Core Team
|
| 53846 |
murrell |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
|
|
6 |
\name{grid.function}
|
| 56186 |
murdoch |
7 |
\alias{grid.function}
|
| 53846 |
murrell |
8 |
\alias{functionGrob}
|
|
|
9 |
\alias{grid.abline}
|
|
|
10 |
\title{Draw a curve representing a function}
|
|
|
11 |
\description{
|
|
|
12 |
Draw a curve representing a function.
|
|
|
13 |
}
|
|
|
14 |
\usage{
|
|
|
15 |
grid.function(...)
|
|
|
16 |
functionGrob(f, n = 101, range = "x", units = "native",
|
|
|
17 |
name = NULL, gp=gpar(), vp = NULL)
|
|
|
18 |
|
| 61433 |
ripley |
19 |
grid.abline(intercept, slope, ...)
|
| 53846 |
murrell |
20 |
}
|
|
|
21 |
\arguments{
|
|
|
22 |
\item{f}{ A function that must take a single argument
|
|
|
23 |
and return a list with two numeric components named \code{x} and
|
|
|
24 |
\code{y}.}
|
|
|
25 |
\item{n}{ The number values that will be generated as input
|
|
|
26 |
to the function \code{f}.}
|
|
|
27 |
\item{range}{ Either \code{"x"}, \code{"y"}, or a numeric vector.
|
|
|
28 |
See the \sQuote{Details} section.}
|
|
|
29 |
\item{units}{A string indicating the units to use
|
|
|
30 |
for the \code{x} and \code{y} values generated by the function.}
|
|
|
31 |
\item{intercept}{ Numeric.}
|
|
|
32 |
\item{slope}{ Numeric. }
|
|
|
33 |
\item{\dots}{ Arguments passed to \code{grid.function()}}
|
|
|
34 |
\item{name}{ A character identifier. }
|
|
|
35 |
\item{gp}{An object of class \code{gpar}, typically the output
|
|
|
36 |
from a call to the function \code{gpar}. This is basically
|
|
|
37 |
a list of graphical parameter settings.}
|
|
|
38 |
\item{vp}{A Grid viewport object (or NULL).}
|
|
|
39 |
}
|
|
|
40 |
\details{
|
|
|
41 |
\code{n} values are generated and passed to the function \code{f}
|
|
|
42 |
and a series of lines are
|
|
|
43 |
drawn through the resulting \code{x} and \code{y} values.
|
|
|
44 |
|
| 61433 |
ripley |
45 |
The generation of the \code{n} values depends on the value of
|
| 53846 |
murrell |
46 |
\code{range}. In the default case, \code{dim} is
|
|
|
47 |
\code{"x"}, which means that a set
|
|
|
48 |
of \code{x} values are generated covering the range of the current
|
|
|
49 |
viewport scale in the x-dimension. If \code{dim} is \code{"y"}
|
|
|
50 |
then values are generated from the current y-scale instead.
|
|
|
51 |
If \code{range} is a numeric vector, then values are generated
|
|
|
52 |
from that range.
|
|
|
53 |
|
|
|
54 |
\code{grid.abline()} provides a simple front-end for a straight
|
|
|
55 |
line parameterized by \code{intercept} and \code{slope}.
|
|
|
56 |
}
|
|
|
57 |
\value{
|
|
|
58 |
A functiongrob grob.
|
|
|
59 |
}
|
|
|
60 |
\author{Paul Murrell}
|
|
|
61 |
\seealso{
|
|
|
62 |
\link{Grid},
|
|
|
63 |
\code{\link{viewport}}
|
|
|
64 |
}
|
|
|
65 |
\examples{
|
|
|
66 |
# abline
|
|
|
67 |
# NOTE: in ROOT viewport on screen, (0, 0) at top-left
|
|
|
68 |
# and "native" is pixels!
|
|
|
69 |
grid.function(function(x) list(x=x, y=0 + 1*x))
|
|
|
70 |
# a more "normal" viewport with default normalized "native" coords
|
|
|
71 |
grid.newpage()
|
|
|
72 |
pushViewport(viewport())
|
|
|
73 |
grid.function(function(x) list(x=x, y=0 + 1*x))
|
|
|
74 |
# slightly simpler
|
|
|
75 |
grid.newpage()
|
|
|
76 |
pushViewport(viewport())
|
|
|
77 |
grid.abline()
|
|
|
78 |
# sine curve
|
|
|
79 |
grid.newpage()
|
|
|
80 |
pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
|
|
|
81 |
grid.function(function(x) list(x=x, y=sin(x)))
|
|
|
82 |
# constrained sine curve
|
|
|
83 |
grid.newpage()
|
|
|
84 |
pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
|
|
|
85 |
grid.function(function(x) list(x=x, y=sin(x)),
|
|
|
86 |
range=0:1)
|
|
|
87 |
# inverse sine curve
|
|
|
88 |
grid.newpage()
|
|
|
89 |
pushViewport(viewport(xscale=c(-1, 1), yscale=c(0, 2*pi)))
|
|
|
90 |
grid.function(function(y) list(x=sin(y), y=y),
|
|
|
91 |
range="y")
|
|
|
92 |
# parametric function
|
|
|
93 |
grid.newpage()
|
|
|
94 |
pushViewport(viewport(xscale=c(-1, 1), yscale=c(-1, 1)))
|
|
|
95 |
grid.function(function(t) list(x=cos(t), y=sin(t)),
|
|
|
96 |
range=c(0, 9*pi/5))
|
|
|
97 |
# physical abline
|
|
|
98 |
grid.newpage()
|
|
|
99 |
grid.function(function(x) list(x=x, y=0 + 1*x),
|
|
|
100 |
units="in")
|
|
|
101 |
}
|
|
|
102 |
\keyword{dplot}
|