I'm preparing a small r-package and I would like to use the function plot()
on an object created through a function, and getting a customized plot. For instance, this is a very silly example function:
myfun <- function(x,y){
A <- B <- c()
for(i in 1:x) {
A[i] <- i^2
B[i] <- i^2+1}
return(list(A,B))
}
Then, I create a list with 2 vectors:
obj <- myfun(5,6)
So, the standard approach to get a plot would be:
plot(x=obj[[1]],y=obj[[2]], main='my title',type = 'b', col='red)
BUT, instead of that, I would like to run the following:
plot(obj)
And get the same. So I don't know how to code that into my function in order to get a completely personalize plot. Also, I would like to get a customized summary table, for instance, running the following:
summary(obj)
Be able to get a table with means, sd, etc. I was looking all over StackOverflow about this, with no success, but maybe I used the wrong keywords. Thanks a lot in advance.