I use the effects
package in R to generate nice effects plots. When one of the predictors in my model is a factor, the plot uses the factor labels as axis tick labels. In some cases this is not ideal, since the factor names may be shortened for ease of typing and viewing in Anova displays, but I'd like a more readable label for the plot.
I tried using the transform.x
argument to plot
, but the documentation says this only works for "numeric predictors", and indeed it doesn't seem to work (there is no effect on the displayed labels).
I specifically do not want to change the factor level names themselves (i.e., change the data), because I have other reasons for wanting them to be what they are. I only want to affect the plot display, not the model itself.
What I want is the ability to specify a mapping between factor levels of a predictor and strings to be used as the axis tick labels for those factor levels. How can I achieve this?
Here is a simple example:
library(effects)
A = rnorm(100)
B = rnorm(100)
C = factor(rep(c("This", "That"), 50))
model = lm(A~B*C)
plot(effect("B:C", model), x.var="C")
That produces this plot:
effect plot http://snag.gy/5mTkJ.jpg
I want to be able to change the x-axis tick labels "This" and "That" to anything I want, without changing the actual factor level names in the vector C.