[R] Interaction plots (six on one page)

ukoenig at med.uni-marburg.de ukoenig at med.uni-marburg.de
Tue Jun 30 22:20:24 CEST 2009


#Dear R users,
#I want six interaction plots to be on one page,
#but the following problem occurs: the legend "BMIakt" appears,
#but it is exactly on the border of the plots (too far right).
#My seccond question is, how I can reduce the empty space in the y-direction
#between the plots.

#Please have a look at my syntax below.

#Many thanks!
#Udo


myData <-
("id,BMIakt,time,thanaa,thalcho,thalino,ponaa,pocho,poino
1,0,1,1.63,0.79,0.28,1.63,0.98,0.58
2,0,2,1.7,0.72,0.37,1.83,0.97,0.42
3,1,1,1.73,0.83,0.32,2.24,1,0.88
4,1,2,1.87,0.76,0.49,1.78,0.68,0.61
5,0,1,1.81,0.99,0.47,1.98,0.96,0.6
6,0,2,1.7,0.77,0.38,1.68,0.79,0.51
7,0,1,1.79,0.95,0.48,1.65,0.9,0.73
8,0,2,2.5,0.79,0.56,2.09,0.81,0.64
9,1,1,1.63,0.71,0.36,2.13,0.98,0.68
10,1,2,1.69,0.85,0.43,2,0.94,0.59
11,1,1,1.95,1.04,0.38,1.7,0.92,0.47
12,1,2,2.16,0.84,0.25,2.01,0.73,0.38
13,0,1,1.65,0.8,0.2,1.74,0.95,0.43
14,0,2,1.83,0.96,0.59,1.88,1.2,0.73
15,1,1,2.02,0.79,0.26,2.01,0.94,0.59
16,1,2,1.71,0.57,0.42,1.87,0.73,0.59
17,1,1,1.5,0.78,0.35,1.68,0.84,0.48
18,1,2,1.4,0.66,0.43,1.87,1.02,0.39
19,1,1,1.45,0.69,0.32,1.74,0.67,0.44
20,1,2,1.65,0.88,0.27,1.7,0.87,0.55
21,1,1,1.89,0.66,0.4,1.93,0.88,0.58
22,1,2,1.71,0.81,0.34,1.87,0.8,0.53
23,1,1,1.71,0.87,0.34,1.65,1.16,0.65
24,1,2,1.82,1.29,0.49,1.98,1.31,0.57
25,1,1,1.66,0.86,0.28,1.4,0.8,0.38
26,1,2,1.82,0.82,0.45,1.4,1.1,0.68
27,1,1,1.67,0.71,0.32,1.83,0.84,0.63
28,1,2,2.06,0.69,0.41,1.62,0.9,0.57
29,1,1,1.62,0.81,0.47,1.88,1.11,0.6
30,1,2,1.76,0.77,0.71,1.74,1.2,0.55
31,0,1,1.8,0.78,0.27,1.96,0.86,0.47
32,0,2,1.7,0.63,0.35,2.22,0.83,0.58
33,1,1,1.92,0.8,0.37,1.8,0.98,0.43
34,1,2,1.94,0.84,0.48,1.92,0.86,0.61
35,1,1,1.55,0.6,0.44,1.78,0.86,0.64
36,1,2,1.68,0.61,0.39,1.84,0.85,0.65
37,0,1,1.77,0.84,0.47,1.72,0.84,0.57
38,0,2,1.79,0.85,0.55,1.89,0.85,0.54
39,1,1,1.87,0.9,0.52,2.01,1.01,0.7
40,1,2,1.91,0.72,0.28,1.81,0.78,0.65")

data <- read.table(textConnection(myData),
      header=TRUE, sep=",", row.names="id")

attach(data)
layout(matrix(1:6, 3, 2))


interaction.plot(time, BMIakt, thanaa)
interaction.plot(time, BMIakt, thalcho)
interaction.plot(time, BMIakt, thalino)
interaction.plot(time, BMIakt, ponaa)
interaction.plot(time, BMIakt, pocho)
interaction.plot(time, BMIakt, poino)


#Using "locator()" would be an alternative, but the text "BMIakt" is missing,
#doing that
interaction.plot(time, BMIakt175, thanaa, legend=FALSE)
legend(locator(1), c("1", "0"), cex=0.8, col=c("black", "black"), lty=1:2)




More information about the R-help mailing list