简体   繁体   English

如何在从线性 model 创建的两个图中独立地 label 两个 x 轴?

[英]How to label two x-axes independently in two plots created from linear model?

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.我们创建了一个线性 model,它在管理测试中获得分数,并将其作为 function 来检查个人是否以英语为母语及其学习年份。

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 function 从影响 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.我没有看到 label 独立 x 轴的方法。 Applying the same ylab to both works since they are illustrating the same score, but the x-axes must be unique.将相同的 ylab 应用于两个作品,因为它们说明了相同的分数,但 x 轴必须是唯一的。 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.我想也许我可以使用 grid.arrange 将它们放在一起,就像在这篇文章中一样,但这似乎只是为了安排多个地块,我已经可以通过 model 本身的性质来做。 This does not allow me to rename the axes independently.这不允许我独立重命名轴。

Would anyone be able to point me in the right direction?有人能指出我正确的方向吗?

Thanks very much!非常感谢!

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.基本上我必须通过使用“selection=1”或“selection=2”来 select 单独的效果图,然后将它们存储为向量。 Then I had to put them back together using grid.arrange from the package (gridExtra), as per this thread.然后我不得不使用来自 package (gridExtra) 的 grid.arrange 将它们重新组合在一起,根据这个线程。

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!谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM