-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task 1.R
87 lines (55 loc) · 2.1 KB
/
Task 1.R
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
library(readxl)
data <- read_excel("D:\\Canada1.xlsx")
# dimension - number of rows and columns
dim(data)
head(data)
tail(data)
print(data)
# column names
names(data)
# no of rows
nrow(data)
print(nrow(data))
# no of columns
ncol(data)
# data types
str(data)
# min value
min(data$`2013`)
# max value
max(data$`2013`)
# display 3 rows and 2 columns
data[1:3, 1:2]
# histogram
hist(data$`2013`)
# 10 breaks
hist(data$`2013`,breaks = 10)
# breaks = Scott Method.
hist(data$`2013`,breaks = "Scott")
# breaks = Freedman-Diaconis Method.
hist(data$`2013`,breaks = "Freedman-Diaconis")
# breaks = specify the number of cells
# limits for x and y axis
# labels for x & y axis
# Name of the graph / header
hist(data$`2013`,breaks = 20, xlim = c(0, 290000), ylim = c(0, 200),
xlab = 'Number of Immigrants', ylab = 'Number of Countries',
main = 'Histogram of Immigration in 2013', col = "darkmagenta", border = "pink")
# The hist() function returns a list with 6 components.
h <- hist(data$`2013`,breaks = 20, xlim = c(0, 290000), ylim = c(0, 200),
xlab = 'Number of Immigrants', ylab = 'Number of Countries',
main = 'Histogram of Immigration in 2013', col = "darkmagenta", border = "pink")
print(h)
# place the counts on top of each cell
text(h$mids,h$counts,labels=h$counts, adj=c(0.5, -0.5))
# breaks = specify the number of cells
hist(data$`2013`,breaks = seq(min(data$`2013`),max(data$`2013`), length.out = 10),
xlim = c(0, 290000), ylim = c(0, 200),
xlab = 'Number of Immigrants', ylab = 'Number of Countries',
main = 'Histogram of Immigration in 2013', col = "skyblue", border = "pink")
# breaks = specify the number of cells
# defining breakpoints between the cells as a vector
hist(data$`2013`,breaks = c(0,25000,50000,75000,100000,125000,150000,175000,200000,225000,250000,275000,300000),
xlim = c(0, 300000), ylim = c(0, 200),
xlab = 'Number of Immigrants', ylab = 'Number of Countries',
main = 'Histogram of Immigration in 2013', col = "skyblue", border = "pink")