Arthur
Arthur

Reputation: 2410

How to customize effect plot in R?

I'm trying to some effects plots to visualize regression results. I'm able to create the plot, but many of the arguments I'm supplying don't seem to affect its appearance. For example, this code produces 3 figures of nearly identical appearance. The multiline and rug settings don't seem to work. Am I doing this correctly? Is there an issue caused by the fact that these are considered "legacy arguments" in the documentation? I'm using R 3.5.1 in RStudio. Many thanks!

data("iris")
m = lm(Petal.Length ~ Petal.Width + Species + Species*Petal.Width, data=iris)
print(plot(effect("Petal.Width*Species", m, x.var="Petal.Width", z.var="Species", multiline=TRUE, rug=FALSE)))
print(plot(effect("Petal.Width*Species", m, x.var="Petal.Width", z.var="Species", multiline=FALSE, rug=FALSE)))
print(plot(effect("Petal.Width*Species", m, x.var="Petal.Width", z.var="Species", multiline=FALSE, rug=TRUE)))

#

Upvotes: 1

Views: 1598

Answers (1)

r2evans
r2evans

Reputation: 160437

You are incorrectly putting the arguments for plot within effects. This works:

m = lm(Petal.Length ~ Petal.Width + Species + Species*Petal.Width, data=iris)
plot(effect("Petal.Width*Species", m), x.var="Petal.Width", z.var="Species", multiline=TRUE, rug=FALSE)
plot(effect("Petal.Width*Species", m), x.var="Petal.Width", z.var="Species", multiline=FALSE, rug=FALSE)
plot(effect("Petal.Width*Species", m), x.var="Petal.Width", z.var="Species", multiline=FALSE, rug=TRUE)

(Notice the paren after m, closing off the argument list for effect.)

Upvotes: 3

Related Questions