grid.function(...)
functionGrob(f, n = 101, range = "x", units = "native",
name = NULL, gp=gpar(), vp = NULL)
grid.abline(intercept, slope, ...)
Arguments
f
A function that must take a single argument
and return a list with two numeric components named x and
y.
n
The number values that will be generated as input
to the function f.
range
Either "x", "y", or a numeric vector.
See the ‘Details’ section.
units
A string indicating the units to use
for the x and y values generated by the function.
intercept
Numeric.
slope
Numeric.
...
Arguments passed to grid.function()
name
A character identifier.
gp
An object of class gpar, typically the output
from a call to the function gpar. This is basically
a list of graphical parameter settings.
vp
A Grid viewport object (or NULL).
Details
n values are generated and passed to the function f
and a series of lines are
drawn through the resulting x and y values.
The generation of the n values depends on the value of
range. In the default case, dim is
"x", which means that a set
of x values are generated covering the range of the current
viewport scale in the x-dimension. If dim is "y"
then values are generated from the current y-scale instead.
If range is a numeric vector, then values are generated
from that range.
grid.abline() provides a simple front-end for a straight
line parameterized by intercept and slope.
Value
A functiongrob grob.
Author(s)
Paul Murrell
See Also
Grid,
viewport
Examples
# abline
# NOTE: in ROOT viewport on screen, (0, 0) at top-left
# and "native" is pixels!
grid.function(function(x) list(x=x, y=0 + 1*x))
# a more "normal" viewport with default normalized "native" coords
grid.newpage()
pushViewport(viewport())
grid.function(function(x) list(x=x, y=0 + 1*x))
# slightly simpler
grid.newpage()
pushViewport(viewport())
grid.abline()
# sine curve
grid.newpage()
pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
grid.function(function(x) list(x=x, y=sin(x)))
# constrained sine curve
grid.newpage()
pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
grid.function(function(x) list(x=x, y=sin(x)),
range=0:1)
# inverse sine curve
grid.newpage()
pushViewport(viewport(xscale=c(-1, 1), yscale=c(0, 2*pi)))
grid.function(function(y) list(x=sin(y), y=y),
range="y")
# parametric function
grid.newpage()
pushViewport(viewport(xscale=c(-1, 1), yscale=c(-1, 1)))
grid.function(function(t) list(x=cos(t), y=sin(t)),
range=c(0, 9*pi/5))
# physical abline
grid.newpage()
grid.function(function(x) list(x=x, y=0 + 1*x),
units="in")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(grid)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/grid/grid.function.Rd_%03d_medium.png", width=480, height=480)
> ### Name: grid.function
> ### Title: Draw a curve representing a function
> ### Aliases: grid.function functionGrob grid.abline
> ### Keywords: dplot
>
> ### ** Examples
>
> # abline
> # NOTE: in ROOT viewport on screen, (0, 0) at top-left
> # and "native" is pixels!
> grid.function(function(x) list(x=x, y=0 + 1*x))
> # a more "normal" viewport with default normalized "native" coords
> grid.newpage()
> pushViewport(viewport())
> grid.function(function(x) list(x=x, y=0 + 1*x))
> # slightly simpler
> grid.newpage()
> pushViewport(viewport())
> grid.abline()
> # sine curve
> grid.newpage()
> pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
> grid.function(function(x) list(x=x, y=sin(x)))
> # constrained sine curve
> grid.newpage()
> pushViewport(viewport(xscale=c(0, 2*pi), yscale=c(-1, 1)))
> grid.function(function(x) list(x=x, y=sin(x)),
+ range=0:1)
> # inverse sine curve
> grid.newpage()
> pushViewport(viewport(xscale=c(-1, 1), yscale=c(0, 2*pi)))
> grid.function(function(y) list(x=sin(y), y=y),
+ range="y")
> # parametric function
> grid.newpage()
> pushViewport(viewport(xscale=c(-1, 1), yscale=c(-1, 1)))
> grid.function(function(t) list(x=cos(t), y=sin(t)),
+ range=c(0, 9*pi/5))
> # physical abline
> grid.newpage()
> grid.function(function(x) list(x=x, y=0 + 1*x),
+ units="in")
>
>
>
>
>
> dev.off()
null device
1
>