Hi, I am trying to find a way to represent my results from an ANCOVA and was thinking of doing boxplots or bargraphs. However, I don´t know how to do these codes with adjusting for the covariate. Does anyone know how?
I believe there is a package called 'LSMEANS' that will compute the (wait for it...) LSMEANS. LSMEANS == adjusted means, it should be at the average value of the continuous covariate. One approach is to plot these LSMEANS. Another is to look at the differences betwixt them, and express everything as the difference from the control category, if there is a good choice of one. hack it a bit, the package is basically self explanatory as I recall but I have not used it in a while as I have been sequestered to SAS these days. GGPLOT2 is the happenin' plot package last time I checked...
Another good plot is just covariate on x by independant on y, color by treatment group.
Here is a worked example using the R dataset iris:
# This will get the marginal means
#This is for ploting
m1 <- lm(Sepal.Length ~ Sepal.Width + Species, iris)
# Get the marginal means. By default will be evaluated at the mean for continuous variables
# and the mode for factors
# The terms argument allows us to focus on a variable of interest.
# In this case the 'grouping' variable
mm_m1 <- ggpredict(m1, terms = "Species")
#Then we plot
ggplot(mm_m1, aes(x = x, y = predicted)) +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high))