return plot and values from a function together

Viewed 5745

I have a function like this:

fun <- function(dataset){
  require(ggplot2)
  g <- ggplot(dataset, aes(x = x, y = y)) + geom_smooth(method = "lm") + geom_point()

l<-lm(y~x)
return (list(l, g))
    }

and I want to return both plot and the values, but it doesn't return the plot and I face this error:

Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) :
invalid graphics state

What can I do?

1 Answers
Related