Search code examples
rplotlattice

Visualize ANCOVA incl formulas (e.g. library HH)


Package HH seems provide a easy way to visualize ANCOVAs

library(HH)
data(hotdog)
ancova(Sodium ~ Calories * Type, data=hotdog)

enter image description here

Is there a comfortable way to combinate this with something like panel.ablineq from latticeExtra? (http://latticeextra.r-forge.r-project.org#panel.ablineq) to get the concrete functions (slope, intercept)?


Solution

  • The general answer will be to use HH::ancovaplot() directly (rather than implicitly via HH::ancova()) along with latticeExtra's handy layer() function and overloaded + operator. I'll leave it to you to work out the fiddly details required to make it look exactly how you want it to.

    ancovaplot(Sodium ~ Calories * Type, data=hotdog) +
    layer(panel.ablineq(lm(y ~ x), rot = TRUE, at = 0.5, pos = 3))
    

    enter image description here