I’m doing a linear fitting on many datasets in a loop and plotting the results in a pdf file. Is it possible to directly save the output of summary(fit) in the same pdf file instead of observing the summaries of about 100 datasets through the console?
LMmodel <- y ~ x
fit <- lm(LMmodel, data = Dataset)
pdf(file = OutputFile, width = 10, height = 6, paper = "a4r")
xLim = range(x)
yLim = range(y)
plot(x, y, type = "p", xlim = xLim, ylim = yLim,
main = plotTitle, xlab = "x [m]", ylab = "y [dB]",
pch = 20, cex = .9)
regLine(fit, col=palette()[2], lwd=2, lty=1)
grid(lwd = 1.5)
plot(density(residuals(fit)), main = "Density Plot of the Residuals"))
dev.off()
graphics.off()
return(summary(fit))
I really recommend Knitr with Rstudio to generate Report.
Here I use you code to generate a pdf in 3 simple steps. I assume you have Rstudio installed.
I create a new R sweave file ( using the menu)
Where I insert 2 chuncks (using the Chunks at right)
the summary is :
You can insert what you want between the summary and the plots to build complex reports.