r - How to use the function variables (x and y) in the plot title that the function creates -


i'm working on creating function graphs linear regressions , residuals. i've created body of function, add more details plot produces, such title , axis labels. specifically, want have title of plot variables input function, this: "y x" y , x name input function. i've tried using paste() , print() accomplish this, hasn't been successful. also, i've been using rnorm(10) produce values x , y, still want title reflect whatever input function, title should "rnorm(10) rnorm(10)" instead turns out "print(y) print(x)". suggestions on correct code use accomplish this?

reslines <- function(x,y)  { x <- x y <- y plot(y~x, pch=20, col=1, title=print(y) print(x)) lm.xy <- lm(y~x) abline(lm.xy) segments(x0 = x, y0 = y, y1 = predict(lm.xy), col = 130) summary(lm.xy) }  reslines(rnorm(10,rnorm(10)) 

try this:

 reslines <- function(x, y) {  # x <- x  # y <- y  plot(y ~ x, pch = 20, col = 1, main = paste(c(substitute(y), "by", substitute(x)), collapse = " "))  lm.xy <- lm(y ~ x)  abline(lm.xy)  segments(x0 = x, y0 = y, y1 = predict(lm.xy), col = 130)  summary(lm.xy) }  reslines(rnorm(10), rnorm(10)) 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -