调整 Johnson-Neyman 图

huangapple go评论53阅读模式
英文:

Adjusting Johnson-Neyman Plots

问题

我使用了interactions包来运行Johnson-Neyman分析以探索交互作用。

我收到了一个输出,包括分析的图表。

我有困难更改一些参数(我认为这不是通常的ggplot语法)。

具体来说,我想要:

  1. 更改x轴和y轴的刻度(使y = -1、0、1,x = 1、2、3、4、5、6、7)。

  2. 更改颜色方案为灰度。

  3. 居中图表标题。

这是我目前的代码:

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 &lt;- read.csv(&quot;C:/Users/Itai/Desktop/1.csv&quot;)

test &lt;- lm(choose_town ~ cond_num * CFNU, data = data)

summary(test)

y &lt;- johnson_neyman(model = test, pred = cond_num, modx = CFNU)

y &lt;- y[[&quot;plot&quot;]]

y[[&quot;labels&quot;]][[&quot;x&quot;]] &lt;- &quot;CNFU&quot;

y[[&quot;labels&quot;]][[&quot;y&quot;]] &lt;- &quot;Donation Destination&quot;

y[[&quot;coordinates&quot;]][[&quot;limits&quot;]][[&quot;x&quot;]] &lt;- c(1, 7)

y[[&quot;coordinates&quot;]][[&quot;limits&quot;]][[&quot;y&quot;]] &lt;- c(-1, 1)

y[[&quot;labels&quot;]][[&quot;title&quot;]] &lt;- &quot;Johnson-Neyman Plot&quot;

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[[&quot;plot&quot;]] so when done and you just want to format your graph you can use ggplot chaining from there.

library(interactions)

states &lt;- as.data.frame(state.x77)

fiti &lt;- lm(Income ~ Illiteracy * Murder + `HS Grad`, data = states)

y &lt;- johnson_neyman(fiti, pred = Illiteracy, modx = Murder, alpha = .05, plot = F)

y[[&quot;plot&quot;]] +
  labs(title = &quot;My new Johnson-Neyman Plot title&quot;, x = &quot;My new x axis&quot;, y = &quot;My new y axis&quot;) +
  xlim(-10, 16) +
  ylim(-1500, 1500) 

huangapple
  • 本文由 发表于 2023年2月8日 21:34:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386568.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定