Hello



I have a data composing three columns: body weight, body length, and sex.

I want to draw a box plot, X-axis for body weight, Y-axis for body length.



In the boxplot,

I want to compare the body length between two sexes of three groups of body
weight: <50, 51-100, >101 kg.

(For instance, from left to right,

the first boxplot: sex =1, body weight <50

the second boxplot: sex =2, body weight <50

the third boxplot: sex =1, body weight 51-100

the fourth boxplot: sex =2, body weight51-100

the fifth boxplot: sex =1, body weight >101

the sixth boxplot: sex =2, body weight >101)



Please kindly advise how to modify the code below for the above purpose.

Thank you.



Elaine



Code

library(HH)



# data input 1 (all data)

    dataN<-read.csv("H:/body_status.csv",header=T, row.names=1)

    dataN$sex <-factor(dataN$sex)

    dim(dataN)

    dataN[1,]

    str(dataN)



    sex.colors <- c("darkblue","red2")

    sex.code <- c("Boy", "Girl")

levels(dataN$sex) <- sex.code



 # graph

    par(mai=c(1,1.03,0.4,0.4))

    par(new=T)



    bwplot(body_length~body_weight, data=dataN,

    xlab=list("Body weight", cex = 1.4),

    ylab=list("Body length",cex = 1.4),

    xaxt="n",

    yaxt="n",type="p",

    lwd=1.5,

    cex.lab=1.4, cex.axis=1.2,

    font.axis=2,

    cex=1.5,

    las=1,

    bty="l",

    panel=panel.bwplot.intermediate.hh,

    col=Diet.colors,

    pch=rep("|",3),

    scales=list(x=list(rot=90)),

    par.settings=list(box.umbrella=list(lty=1)))



data



No

body_weight

body_length

Sex

1

87

154

1

2

76

189

2

3

54

176

2

4

87

162

2

5

67

190

2

6

89

143

1

7

73

167

2

8

86

189

2

9

90

196

1

10

94

154

1

11

61

167

2

12

102

180

2

13

106

193

1

14

110

206

2

15

114

219

2

16

118

156

2

17

122

198

2

18

87

187

1

19

67

174

1

20

46

179

2

21

54

164

1

22

98

167

1

23

93

198

1

24

62

201

1

25

60

173

1

26

78

165

1

27

75

169

2

28

66

178

1

29

42

174

1

30

90

178

2

31

105

172

2

32

118

180

1

33

94

187

2

34

85

176

1

35

72

145

2

36

66

165

2

37

56

162

2

38

89

159

2

39

73

167

1

40

52

190

1

41

51

154

1

42

98

176

2

43

74

172

2

44

78

171

2

45

97

173

1

46

45

167

2

47

46

163

2

48

107

164

1

49

93

160

2

	[[alternative HTML version deleted]]


