1

I apologize if this has been asked before, I'm sure there is a simple way to do this, but I have tried to search the forum and I can't find the answer.

We have created a linear model which takes a score on an administered test and examines it as a function of whether or not an individual is a native speaker of English and their year of study.

art_mod1A = lm(art_score ~ native + year, data = art, subset = abs(scale(resid(art_mod1)))<2.5)

Then we want to plot it out, using the allEffects function from the effects package.

plot(allEffects(art_mod1A), colors = "black", ylab = "ART Score", main = "")

This produces two plots in one image, like this.

What I don't see is a way to label the x-axes independently. Applying the same ylab to both works since they are illustrating the same score, but the x-axes must be unique. Specifically, "Nativeness" on the left and "Year of Study" on the right.

I thought perhaps I could use grid.arrange to put them together, as in this post, but it seems this is only for arranging multiple plots, which I can already do by nature of the model itself. This does not allow me to rename the axes independently.

Would anyone be able to point me in the right direction?

Thanks very much!

Sean
  • 21
  • 3
  • Have you tried providing your `xlab` in a vector? E.g. `xlab = c("foo", "bar")` – Frédéric Apr 22 '20 at 18:55
  • Hi there, that's an interesting notion which I hadn't thought of. Just tried it, and unfortunately it just assigns both of the names in the vector to both plots, so for example they're both labelled "foo bar". Still not sure how to separate the x-axis label for the left plot from the right plot. Hmm... – Sean Apr 22 '20 at 19:10
  • Another guess then: have you tried exploring the documentation of the `plot` function associated to the `allEffects` function you're using? I assume it comes from a package, and the `plot` is a generic function? – Frédéric Apr 22 '20 at 19:11
  • Have you thought about converting from base R to `ggplot2`? You'll have a lot more flexibility and you should be able facet the plots and customize the x-axis accordingly. – Tim Assal Apr 22 '20 at 19:34

1 Answers1

1

I figured it out! I will leave this up as a testament to my foolishness.

Basically I had to select the individual effects plots by using "selection=1" or "selection=2", then storing them as vectors. Then I had to put them back together using grid.arrange from the package (gridExtra), as per this thread.

So the code was like this:

artplot1 <- plot(allEffects(art_mod1A), selection=2, multiline= T, main = "", ylab = "ART Score", xlab = "Year of Study", colors = c("black", "darkgrey"), confint = list(style = "bars", 
                                                                                                                                                 alpha = 0.15))
artplot2 <- plot(allEffects(art_mod1A), selection=1, multiline= T, main = "", ylab = "ART Score", xlab = "Nativeness", colors = c("black", "darkgrey"), confint = list(style = "bars", alpha = 0.15))

library(gridExtra)
grid.arrange(artplot2, artplot1,  nrow=1,  ncol=2)

Thank you for your help!

Sean
  • 21
  • 3