![](/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.