英文:
Adjusting Johnson-Neyman Plots
问题
我使用了interactions包来运行Johnson-Neyman分析以探索交互作用。
我收到了一个输出,包括分析的图表。
我有困难更改一些参数(我认为这不是通常的ggplot语法)。
具体来说,我想要:
-
更改x轴和y轴的刻度(使y = -1、0、1,x = 1、2、3、4、5、6、7)。
-
更改颜色方案为灰度。
-
居中图表标题。
这是我目前的代码:
library(interactions)
data <- read.csv("C:/Users/Itai/Desktop/1.csv")
test <- lm(choose_town ~ cond_num * CFNU, data = data)
summary(test)
y <- johnson_neyman(model = test, pred = cond_num, modx = CFNU)
y <- y[["plot"]]
y[["labels"]][["x"]] <- "CNFU"
y[["labels"]][["y"]] <- "Donation Destination"
y[["coordinates"]][["limits"]][["x"]] <- c(1, 7)
y[["coordinates"]][["limits"]][["y"]] <- c(-1, 1)
y[["labels"]][["title"]] <- "Johnson-Neyman Plot"
y
英文:
I used the interactions package to run a Johnson-Neyman analysis to probe an interaction.
I received an output including a plot of the analysis.
I struggle to change some of the parameters (I think this is not a usual ggplot syntax).
Specifically, I want to:
Change the scaling on the x and y axis (so y = -1, 0, 1 and x = 1, 2, 3, 4, 5, 6, 7)
Change the color scheme to grayscale.
Center the plot title.
This is my code so far:
library(interactions)
data <- read.csv("C:/Users/Itai/Desktop/1.csv")
test <- lm(choose_town ~ cond_num * CFNU, data = data)
summary(test)
y <- johnson_neyman(model = test, pred = cond_num, modx = CFNU)
y <- y[["plot"]]
y[["labels"]][["x"]] <- "CNFU"
y[["labels"]][["y"]] <- "Donation Destination"
y[["coordinates"]][["limits"]][["x"]] <- c(1, 7)
y[["coordinates"]][["limits"]][["y"]] <- c(-1, 1)
y[["labels"]][["title"]] <- "Johnson-Neyman Plot"
y
答案1
得分: 2
我没有您的数据,所以我使用他们的示例之一。他们的文档有点混乱,是的,他们返回一个ggplot
对象,但y
本身无法像您在ggplot2
中习惯的那样进行链接。
您已经注意到ggplot
部分位于y[["plot"]]
中,所以当完成后,如果您只想格式化您的图形,可以从那里使用ggplot
链。
library(interactions)
states <- as.data.frame(state.x77)
fiti <- lm(Income ~ Illiteracy * Murder + `HS Grad`, data = states)
y <- johnson_neyman(fiti, pred = Illiteracy, modx = Murder, alpha = .05, plot = F)
y[["plot"]] +
labs(title = "My new Johnson-Neyman Plot title", x = "My new x axis", y = "My new y axis") +
xlim(-10, 16) +
ylim(-1500, 1500)
注意:代码部分未被翻译。
英文:
I do not have your data, so I use one of their examples instead. Their documentation is a bit confusing and yes they return a ggplot
object, but y
itself cannot be chained as you are used to in ggplot2
You already noticed that the ggplot part resides in y[["plot"]]
so when done and you just want to format your graph you can use ggplot chaining from there.
library(interactions)
states <- as.data.frame(state.x77)
fiti <- lm(Income ~ Illiteracy * Murder + `HS Grad`, data = states)
y <- johnson_neyman(fiti, pred = Illiteracy, modx = Murder, alpha = .05, plot = F)
y[["plot"]] +
labs(title = "My new Johnson-Neyman Plot title", x = "My new x axis", y = "My new y axis") +
xlim(-10, 16) +
ylim(-1500, 1500)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论