![](/img/trans.png)
[英]What is the difference between autoplot function and plot function in R
[英]What is the difference between curve and plot function in R?
f1<-function(t)
{
sqrt((t^2)+1)
}
curve(f1,from=0,to = 5,n=10)
plot(f1,from=0,to = 5,n=10)
给出相同的输出。 那么,曲线和情节函数有什么区别?
功能不是很多。 plot
最终称为curve
。
plot
是一个泛型函数,意味着它有多个方法,具体取决于传递给它的对象类(在本例中是一个函数)。 要找出特定方法背后的代码,可以键入graphcs:::plot.<method>
。
在这种情况下,你可以看到plot
当应用于函数首先检查和之前最终只是打电话调整其参数curve
。
> graphics:::plot.function
function (x, y = 0, to = 1, from = y, xlim = NULL, ylab = NULL,
...)
{
if (!missing(y) && missing(from))
from <- y
if (is.null(xlim)) {
if (is.null(from))
from <- 0
}
else {
if (missing(from))
from <- xlim[1L]
if (missing(to))
to <- xlim[2L]
}
if (is.null(ylab)) {
sx <- substitute(x)
ylab <- if (mode(x) != "name")
deparse(sx)[1L]
else {
xname <- list(...)[["xname"]]
if (is.null(xname))
xname <- "x"
paste0(sx, "(", xname, ")")
}
}
curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,
...)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.