I am trying to create interaction plots from my data of a factorial design, but the lines do not show up. My data frame is
dr
Nr. Bruch Keimf Einw Temp Zeit
1 h1 2.63 54 0 30 4
2 h2 1.71 51 4 30 4
3 h3 2.37 56 0 50 4
4 h4 4.00 51 4 50 4
5 h5 1.63 55 0 30 10
6 h6 1.47 55 4 30 10
7 h7 3.11 43 0 50 10
8 h8 2.42 60 4 50 10
9 c1 2.07 51 2 40 7
10 c2 2.37 46 2 40 7
11 c3 2.48 39 2 40 7
my code for the plot is
dr$temp=factor(dr$Temp)
interaction.plot(dr$Zeit,dr$Temp,dr$Keimf,
main="Interactionplot Zeit*Temp",
xlab="Zeit (h)", ylab="Keimf (%)", col="olivedrab3", lwd=3, trace.label=deparse(substitute(Temperatur)))
and I get following graph as expected, but not showing lines
[][1]
[1]: https://i.sstatic.net/u18KA.png
I checked https://rdrr.io/r/stats/interaction.plot.html and thought the problem might be, that the yaxis is not covering all values, however adding
ylim=c(30,65)
resulted in error messages and did not work. I found another example for interactionplot within the forum How to clinch the legend of an interaction.plot? but the overall code is too nested and complicated to get through it, as being new to r. Do you think the yaxis is the problem or is there something else I oversaw?
Per your comment yes it was a lack of data. Here's an example with mock data that shows your code is good as well a custom interaction plotting function you may like.
Fake some data. Use your code.
mock_dr <- data.frame(
Temp = sample(x = c(30, 40, 50), size = 45, replace = TRUE),
Zeit = sample(x = c(4, 7, 10), size = 45, replace = TRUE),
Keimf = sample(x = 39:60, size = 45, replace = TRUE)
)
interaction.plot(mock_dr$Zeit, mock_dr$Temp, mock_dr$Keimf,
main="Interactionplot Zeit*Temp",
xlab="Zeit (h)", ylab="Keimf (%)", col="olivedrab3", lwd=3, trace.label=deparse(substitute(Temperatur)))
A custom function you mat find useful in the future
CGPfunctions::Plot2WayANOVA(Keimf ~ Zeit * Temp, mock_dr)
#> Converting Zeit to a factor --- check your results
#>
#> Converting Temp to a factor --- check your results
#> Warning in qt(confidence/2 + 0.5, n() - 1): NaNs produced
#>
#> --- WARNING! ---
#> You have an unbalanced design. Using Type II sum of
#> squares, to calculate factor effect sizes eta and omega.
#> Your two factors account for 0.204 of the type II sum of
#> squares.
#> term sumsq meansq df statistic p.value etasq partial.etasq
#> Zeit Zeit 203.060 101.530 2 2.818 0.073 0.125 0.135
#> Temp Temp 102.773 51.386 2 1.426 0.253 0.063 0.073
#> Zeit:Temp Zeit:Temp 27.253 6.813 4 0.189 0.943 0.017 0.021
#> ...4 Residuals 1297.086 36.030 36 NA NA NA NA
#> omegasq partial.omegasq epsilonsq cohens.f power
#> Zeit 0.079 0.075 0.080 0.396 0.554
#> Temp 0.018 0.019 0.019 0.281 0.307
#> Zeit:Temp -0.070 -0.078 -0.072 0.145 0.091
#> ...4 NA NA NA NA NA
#>
#> Measures of overall model fit
#> # A tibble: 1 x 5
#> logLik AIC BIC deviance nobs
#> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 -139. 299. 317. 1297. 45
#>
#> Table of group means
#> # A tibble: 9 x 15
#> # Groups: Zeit [3]
#> Zeit Temp TheMean TheSD TheSEM CIMuliplier LowerBoundCI UpperBoundCI
#> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 4 30 53.2 3.27 1.46 2.78 49.1 57.3
#> 2 4 40 49 NA NA NaN NA NA
#> 3 4 50 54.3 3.21 1.86 4.30 46.3 62.3
#> 4 7 30 48.7 5.05 2.06 2.57 43.4 54.0
#> 5 7 40 48 6.32 2.58 2.57 41.4 54.6
#> 6 7 50 52.6 4.83 2.16 2.78 46.6 58.6
#> 7 10 30 47.9 7.54 2.85 2.45 40.9 54.8
#> 8 10 40 44.7 7.59 2.87 2.45 37.7 51.7
#> 9 10 50 47.8 5.63 2.52 2.78 40.8 54.8
#> # … with 7 more variables: LowerBoundSEM <dbl>, UpperBoundSEM <dbl>,
#> # LowerBoundSD <dbl>, UpperBoundSD <dbl>, N <int>, LowerBound <dbl>,
#> # UpperBound <dbl>
#>
#> Post hoc tests for all effects that were significant
#> [1] "No signfiicant effects"
#>
#> Testing Homogeneity of Variance with Brown-Forsythe
#> Levene's Test for Homogeneity of Variance (center = median)
#> Df F value Pr(>F)
#> group 8 0.5877 0.7812
#> 36
#>
#> Testing Normality Assumption with Shapiro-Wilk
#>
#> Shapiro-Wilk normality test
#>
#> data: MyAOV_residuals
#> W = 0.95464, p-value = 0.07623
#>
#> Interaction graph plotted...