2015-12-02 54 views
1

我经常使用scatter.smooth函数,但我想知道是否可以直接将titlemain参数添加到此函数中。我阅读了功能的描述,但没有找到可能性。我知道还有其他方法可以做到这一点,但如果可能的话我想保留这一点。是否可以为scatter.smooth添加标题?

d <- data.frame(x = sample(20, 500, prob=c(1:10, 10:1), replace = TRUE), 
       y = sample(20, 500, prob=c(1:10, 10:1), replace = TRUE), 
       z = rnorm(500, 20, 4)) 
mo <- lm(y ~ z, d) 
fig <- function(x) { 
    scatter.smooth(fitted(x), residuals(x, type = "response"), col = "red") 
    abline(0, 0, lty = 2) 
    legend("topright", legend = c("loss", "0-0"), lty = c(1, 2)) 
} 
fig(mo) 
+1

函数'scatter.smooth()'可用作R-source。它没有'title'和'main'的参数。恕我直言,在这方面的功能类似于'points()'。 – jogo

回答

2

你看看scatter.smooth帮助页面,你看到...参数传递给plot。因此,您可以通过plot接受任何论点。也main=

您也可以添加标题使用mtext这将文本添加到图中的任何利润曲线。

所以,你可以这样做:

fig(mo) 
mtext("My title", side=3, line=1) 

或修改fig功能:

fig <- function(x, ...) { 
    scatter.smooth(fitted(x), residuals(x, type = "response"), 
    col = "red", ...) 
    abline(0, 0, lty = 2) 
    legend("topright", legend = c("loss", "0-0"), lty = c(1, 2)) 
} 
fig(mo, main="My title") 
1

只需添加mainsmooth功能:

scatter.smooth(x, y, ylab = "Yname", xlab = "Xname", main = "Title") 

它的工作原理

相关问题