grid.function | R Documentation |

Draw a curve representing a function.

grid.function(...) functionGrob(f, n = 101, range = "x", units = "native", name = NULL, gp=gpar(), vp = NULL) grid.abline(intercept, slope, ...)

`f` |
A function that must take a single argument
and return a list with two numeric components named |

`n` |
The number values that will be generated as input
to the function |

`range` |
Either |

`units` |
A string indicating the units to use
for the |

`intercept` |
Numeric. |

`slope` |
Numeric. |

`...` |
Arguments passed to |

`name` |
A character identifier. |

`gp` |
An object of class |

`vp` |
A Grid viewport object (or NULL). |

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

.

A functiongrob grob.

Paul Murrell

Grid,
`viewport`

# 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")

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.