-
Notifications
You must be signed in to change notification settings - Fork 0
/
sex.Rmd
174 lines (143 loc) · 3.21 KB
/
sex.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
---
title: "R Notebook"
output:
html_notebook: default
html_document: default
pdf_document: default
---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Cmd+Shift+Enter*.
```{r}
plot(cars)
```
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Cmd+Option+I*.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Cmd+Shift+K* to preview the HTML file).
The data contains the number of men per 100 women for the entire population.
```{r}
sex <- read.csv('sex.csv', sep = ",")
```
```{r}
summary(sex)
```
```{r}
library(ggplot2)
```
```{r}
qplot(x = X2005, data = sex) +
scale_x_continuous(limits = c(80, 120))
```
```{r}
qplot(x = X2015, data = sex) +
scale_x_continuous(limits = c(80, 120))
```
```{r}
f1 <- qplot(X2005, data = sex, geom = "freqpoly", binwidth = 1) +
scale_x_continuous(limits = c(90, 110))
```
```{r}
f2 <- qplot(X2015, data = sex, geom = "freqpoly", binwidth = 1) +
scale_x_continuous(limits = c(90, 110))
```
```{r}
grid.arrange(f1, f2, ncol = 2)
```
One could distinguish a certain change of trend between 2005 and 2015, with a significant spike at the point 100 in the latter.
```{r}
india <- sex[91, 2:22]
```
```{r}
pakistan <- sex[155, 2:22]
```
```{r}
sri_lanka <- sex[192, 2:22]
```
```{r}
poland <- sex[161, 2:22]
```
```{r}
belarus <- sex[18, 2:22]
```
```{r}
czech_republic <- sex[52, 2:22]
```
```{r}
ireland <- sex[95, 2:22]
```
```{r}
iceland <- sex[90, 2:22]
```
```{r}
norway <- sex[151, 2:22]
```
```{r}
b1 <- qplot(x = 1,
y = unlist(india),
geom = "boxplot",
xlab = "India") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b2 <- qplot(x = 1,
y = unlist(pakistan),
geom = "boxplot",
xlab = "Pakistan") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b3 <- qplot(x = 1,
y = unlist(sri_lanka),
geom = "boxplot",
xlab = "Sri Lanka") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b4 <- qplot(x = 1,
y = unlist(poland),
geom = "boxplot",
xlab = "Poland") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b5 <- qplot(x = 1,
y = unlist(belarus),
geom = "boxplot",
xlab = "Belarus") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b6 <- qplot(x = 1,
y = unlist(czech_republic),
geom = "boxplot",
xlab = "Czech Republic") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b7 <- qplot(x = 1,
y = unlist(ireland),
geom = "boxplot",
xlab = "Ireland") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b8 <- qplot(x = 1,
y = unlist(iceland),
geom = "boxplot",
xlab = "Iceland") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
b9 <- qplot(x = 1,
y = unlist(norway),
geom = "boxplot",
xlab = "Norway") +
coord_cartesian(ylim = c(90, 110))
```
```{r}
grid.arrange(b1, b2, b3, b4, b5, b6, b7, b8, b9, ncol = 3)
```
```{r}
qplot(x = 1,
y = unlist(belarus),
geom = "boxplot",
xlab = "Belarus")
```