I have the following toy example of what I am trying to achieve:
library ("lattice")
library ("latticeExtra")
data (iris)
xyplot(Sepal.Width ~ Sepal.Length | Species, data = iris, panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.lmlineq(x, y, adj = c(1,0),
lty = 1,col.text='red', pos= 4,
col.line = "blue", digits = 1,r.squared =TRUE)
panel.text(7, 4, round(cor(x, y),3), font=2, adj=c(0.5,-0.6))
panel.text(7, 4, round(cor.test(x,y)$p.value, 3), font=1, adj=c(0.5,0.6))},
xlab = "Sepal.Length", ylab = "Sepal_Width")
So, as you can see, I have a data frame with levels (Species
) that I'd like to plot (all at the same time) showing their regression line with the R-squared value and also printing their cor()
and cor.test()
outputs. Preferably, in an aesthetically pleasing manner.
Has anyone tried to do something similar? Is there an efficient way to do it?