Does anyone know the equivalent of panel.lmlineq and panel.text (from lattice) in ggplot2?

22 views
Skip to first unread message

MEC

unread,
Jan 19, 2017, 2:29:55 PM1/19/17
to ggplot2

Community and GGPLOT2's Fans:

Sorry for this very basic question, I am new to R and new to ggplot2


I have the following toy code to use an 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")


This codes generates an image (that I can't post), but you'll be able to see if you use the code.

So, as you can see, I have a df with levels (Species) that I'd like to plot (all at the same time) showing their regression line with the Rsquared and also printing their cor and cor.test outputs. Preferably, in an aesthetically pleasing manner.

Has anyone tried to do something similiar? Is there an efficient way to do it?


Originally @stackoverflow


Many thanks, any help will be much appreciated

Hadley Wickham

unread,
Jan 23, 2017, 11:56:44 AM1/23/17
to MEC, ggplot2
Try ggpmisc: http://www.ggplot2-exts.org/ggpmisc.html
Hadley
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://hadley.nz
Reply all
Reply to author
Forward
0 new messages