Blame view

ISO27001effectiveness/R/ReportGraphs.R 10.5 KB
Miguel Tuñón authored
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
GetAttacksEvolution <- function(Attacks){

  attacks.evol <- mutate(Attacks, Year = format(Attacks$Date, "%Y")) %>% group_by(Year)
  attacks.evol <- as.data.frame(table(attacks.evol$Year))
  colnames(attacks.evol) <- c("Year","Attacks")

  graph1 <- ggplot2::qplot(main = "Cyberattacks evolution",
                           x = attacks.evol$Year,
                           y = attacks.evol$Attacks,
                           group = 1,
                           xlab = "Years",
                           ylab = "Attacks",
                           data = attacks.evol,
                           geom = "line")  +
            geom_point() +
            geom_label(aes(label=attacks.evol$Attacks),
                       vjust=c(1.5, 0, 0, -0.5, -0.5),
                       hjust=c(0.5, -0.5, 1.5, 0, 0))+
            theme(plot.title = element_text(hjust = 0.5))

  graph1

}

GetCertsEvolution <- function(Certs){

  Certs.evol <- data.frame(Year = c(2011, 2012, 2013, 2014, 2015),
                  Certs = c(sum(Certs$X2011),
                            sum(Certs$X2012),
                            sum(Certs$X2013),
                            sum(Certs$X2014),
                            sum(Certs$X2015)))

  graph1 <- ggplot2::qplot(main = "ISO 27001 evolution",
                           x = Certs.evol$Year,
                           y = Certs.evol$Certs,
                           group = 1,
                           xlab = "Years",
                           ylab = "Certifications",
                           data = Certs.evol,
                          geom = "line") +
            geom_point() +
            geom_label(aes(label=Certs.evol$Certs),
                       vjust=c(0.2, -0.7, 0, 0, 0.5),
                       hjust=c(-0.6, 1, 1.2, 1.2, 1.2))+
            theme(plot.title = element_text(hjust = 0.5))

  graph1

}


GetAttacksMonthEvolution <- function(Attacks){

  attacks.evol <- mutate(Attacks, Year = format(Attacks$Date, "%Y-%m")) %>% group_by(Year)
  attacks.evol <- as.data.frame(table(attacks.evol$Year))
  colnames(attacks.evol) <- c("Year","Attacks")

  graph1 <- ggplot2::qplot(main = "Cyberattacks evolution",
                           x = attacks.evol$Year,
                           y = attacks.evol$Attacks,
                           group = 1,
                           xlab = "Months",
                           ylab = "Attacks",
                           data = attacks.evol,
                           geom = "line")  +
    geom_point() +
    theme(plot.title = element_text(hjust = 0.5)) +
    geom_smooth(method = 'loess') +
    scale_x_discrete(labels = c("2012", "", "", "", "", "", "", "", "", "", "", "",
                                "2013", "", "", "", "", "", "", "", "", "", "", "",
                                "2014", "", "", "", "", "", "", "", "", "", "", "",
                                "2015", "", "", "", "", "", "", "", "", "", "", "",
                                "2016", "", "", "", "", "", "", "", "", "", "", ""))

  graph1

}
Miguel Tuñón authored
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
GetBaseCertsGraph <- function(Cert_PerCountry, year){
  graph1 <- ggplot2::qplot(main = "Countries with above average number of companies certified with 27001 (2012)",
                           x = reorder(country_short,X2012),
                           y = X2012,
                           xlab = "Country",
                           ylab = "Number of certifications",
                           data = Cert_PerCountry[Cert_PerCountry$X2012 > mean(Cert_PerCountry$X2012),],
                           geom = "col",
                           fill = Continent)
  graph1
}
Miguel Tuñón authored
98
99
100
101
102
103
104
105
#' Return every graph used in the report file
#'
#' @param Cert_PerCountry data.frame with the processed data of ISO 27001 certifications
#' @param Attacks data.frame with the processed data of cyberattacks
#'
#' @return data.frame
#' @export
GetReportGraphs <- function(Cert_PerCountry,Attacks) {
Imanol-Mikel Barba Sabariego authored
106
  #2012
Miguel Tuñón authored
107
  graph1 <- ggplot2::qplot(main = "Countries with above average number of companies certified with 27001 (2012)",
Imanol-Mikel Barba Sabariego authored
108
109
                  x = reorder(country_short,X2012),
                  y = X2012,
Miguel Tuñón authored
110
111
                  xlab = "Country",
                  ylab = "Number of certifications",
Miguel Tuñón authored
112
113
114
115
                  data = Cert_PerCountry[Cert_PerCountry$X2012 > mean(Cert_PerCountry$X2012),],
                  geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
116
117
118
  attacks2k12 <- Attacks[Attacks$Date < "2013-01-01" & Attacks$Date >= "2012-01-01",]
  frameAttacks2k12 <- as.data.frame(table(attacks2k12$Country))
  colnames(frameAttacks2k12) <- c("Country","Attacks")
Miguel Tuñón authored
119
  graph2 <- ggplot2::qplot(main = "Countries with above average number of cyberattacks (2012)",
Imanol-Mikel Barba Sabariego authored
120
121
                  x = reorder(Country,Attacks),
                  y = Attacks,
Miguel Tuñón authored
122
123
                  xlab = "Country",
                  ylab = "Number of attacks",
Miguel Tuñón authored
124
125
126
                  data = frameAttacks2k12[frameAttacks2k12$Attacks > mean(frameAttacks2k12$Attacks),],
                  geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
127
128
129
130

  Attacks2012ByMonth <- mutate(attacks2k12, month = format(attacks2k12$Date, "%m")) %>% group_by(month)
  Attack2012FreqByMonth <- as.data.frame(table(Attacks2012ByMonth$month))
  colnames(Attack2012FreqByMonth) <- c("Month", "Attacks")
Miguel Tuñón authored
131
132
  graph3 <- ggplot2::qplot(x = as.numeric(Month),
                  y = Attacks,
Imanol-Mikel Barba Sabariego authored
133
134
135
136
                  main = "Global cyberattack progression by month (2012)",
                  data = Attack2012FreqByMonth,
                  geom = c("point", "smooth"),
                  xlim = c(1,12),
Miguel Tuñón authored
137
                  xlab = "Month") + ggplot2::scale_x_continuous(breaks = 1:12)
Imanol-Mikel Barba Sabariego authored
138
139

  #2013
Miguel Tuñón authored
140
  graph4 <- ggplot2::qplot(main = "Countries with above average number of companies certified with 27001 (2013)",
Imanol-Mikel Barba Sabariego authored
141
142
                  x = reorder(country_short,X2013),
                  y = X2013,
Miguel Tuñón authored
143
144
                  xlab = "Country",
                  ylab = "Number of certifications",
Miguel Tuñón authored
145
146
147
                  data = Cert_PerCountry[Cert_PerCountry$X2013 > mean(Cert_PerCountry$X2013),]
                  , geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
148
149
150
  attacks2k13 <- Attacks[Attacks$Date < "2014-01-01" & Attacks$Date >= "2013-01-01",]
  frameAttacks2k13 <- as.data.frame(table(attacks2k13$Country))
  colnames(frameAttacks2k13) <- c("Country","Attacks")
Miguel Tuñón authored
151
  graph5 <- ggplot2::qplot(main = "Countries with above average number of cyberattacks (2013)",
Imanol-Mikel Barba Sabariego authored
152
153
                  x = reorder(Country,Attacks),
                  y = Attacks,
Miguel Tuñón authored
154
155
                  xlab = "Country",
                  ylab = "Number of attacks",
Miguel Tuñón authored
156
157
158
                  data = frameAttacks2k13[frameAttacks2k13$Attacks > mean(frameAttacks2k13$Attacks),]
                  , geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
159
160
161
162

  Attacks2013ByMonth <- mutate(attacks2k13, month = format(attacks2k13$Date, "%m")) %>% group_by(month)
  Attack2013FreqByMonth <- as.data.frame(table(Attacks2013ByMonth$month))
  colnames(Attack2013FreqByMonth) <- c("Month", "Attacks")
Miguel Tuñón authored
163
164
  graph6 <- ggplot2::qplot(x = as.numeric(Month),
                  y = Attacks,
Imanol-Mikel Barba Sabariego authored
165
166
167
168
                  main = "Global cyberattack progression by month (2013)",
                  data = Attack2013FreqByMonth,
                  geom = c("point", "smooth"),
                  xlim = c(1,12),
Miguel Tuñón authored
169
                  xlab = "Month") + ggplot2::scale_x_continuous(breaks = 1:12)
Imanol-Mikel Barba Sabariego authored
170
171

  #2014
Miguel Tuñón authored
172
  graph7 <- ggplot2::qplot(main = "Countries with above average number of companies certified with 27001 (2014)",
Imanol-Mikel Barba Sabariego authored
173
174
                  x = reorder(country_short,X2014),
                  y = X2014,
Miguel Tuñón authored
175
176
                  xlab = "Country",
                  ylab = "Number of certifications",
Miguel Tuñón authored
177
178
179
                  data = Cert_PerCountry[Cert_PerCountry$X2014 > mean(Cert_PerCountry$X2014),]
                  , geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
180
181
182
  attacks2k14 <- Attacks[Attacks$Date < "2015-01-01" & Attacks$Date >= "2014-01-01",]
  frameAttacks2k14 <- as.data.frame(table(attacks2k14$Country))
  colnames(frameAttacks2k14) <- c("Country","Attacks")
Miguel Tuñón authored
183
  graph8 <- ggplot2::qplot(main = "Countries with above average number of cyberattacks (2014)",
Imanol-Mikel Barba Sabariego authored
184
185
                  x = reorder(Country,Attacks),
                  y = Attacks,
Miguel Tuñón authored
186
187
                  xlab = "Country",
                  ylab = "Number of attacks",
Miguel Tuñón authored
188
189
190
                  data = frameAttacks2k14[frameAttacks2k14$Attacks > mean(frameAttacks2k14$Attacks),]
                  , geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
191
192
193
194

  Attacks2014ByMonth <- mutate(attacks2k14, month = format(attacks2k14$Date, "%m")) %>% group_by(month)
  Attack2014FreqByMonth <- as.data.frame(table(Attacks2014ByMonth$month))
  colnames(Attack2014FreqByMonth) <- c("Month", "Attacks")
Miguel Tuñón authored
195
196
  graph9 <- ggplot2::qplot(x = as.numeric(Month),
                  y = Attacks,
Imanol-Mikel Barba Sabariego authored
197
198
199
200
                  main = "Global cyberattack progression by month (2014)",
                  data = Attack2014FreqByMonth,
                  geom = c("point", "smooth"),
                  xlim = c(1,12),
Miguel Tuñón authored
201
                  xlab = "Month") + ggplot2::scale_x_continuous(breaks = 1:12)
Imanol-Mikel Barba Sabariego authored
202
203

  #2015
Miguel Tuñón authored
204
  graph10 <- ggplot2::qplot(main = "Countries with above average number of companies certified with 27001 (2015)",
Imanol-Mikel Barba Sabariego authored
205
206
                  x = reorder(country_short,X2015),
                  y = X2015,
Miguel Tuñón authored
207
208
                  xlab = "Country",
                  ylab = "Number of certifications",
Miguel Tuñón authored
209
210
211
                  data = Cert_PerCountry[Cert_PerCountry$X2015 > mean(Cert_PerCountry$X2015),]
                  , geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
212
213
214
  attacks2k15 <- Attacks[Attacks$Date < "2016-01-01" & Attacks$Date >= "2015-01-01",]
  frameAttacks2k15 <- as.data.frame(table(attacks2k15$Country))
  colnames(frameAttacks2k15) <- c("Country","Attacks")
Miguel Tuñón authored
215
  graph11 <- ggplot2::qplot(main = "Countries with above average number of cyberattacks (2015)",
Imanol-Mikel Barba Sabariego authored
216
217
                  x = reorder(Country,Attacks),
                  y = Attacks,
Miguel Tuñón authored
218
219
                  xlab = "Country",
                  ylab = "Number of attacks",
Miguel Tuñón authored
220
221
222
                  data = frameAttacks2k15[frameAttacks2k15$Attacks > mean(frameAttacks2k15$Attacks),]
                  , geom = "col",
                  fill = Continent)
Imanol-Mikel Barba Sabariego authored
223
224
225
226

  Attacks2015ByMonth <- mutate(attacks2k15, month = format(attacks2k15$Date, "%m")) %>% group_by(month)
  Attack2015FreqByMonth <- as.data.frame(table(Attacks2015ByMonth$month))
  colnames(Attack2015FreqByMonth) <- c("Month", "Attacks")
Miguel Tuñón authored
227
  graph12 <- ggplot2::qplot(x = as.numeric(Month),
Imanol-Mikel Barba Sabariego authored
228
229
230
231
232
                  y = Attacks,
                  main = "Global cyberattack progression by month (2015)",
                  data = Attack2015FreqByMonth,
                  geom = c("point", "smooth"),
                  xlim = c(1,12),
Miguel Tuñón authored
233
                  xlab = "Month") + ggplot2::scale_x_continuous(breaks = 1:12)
Imanol-Mikel Barba Sabariego authored
234
235
236
237
238
239




  list(graph1,graph2,graph3,graph4,graph5,graph6,graph7,graph8,graph9,graph10,graph11,graph12)
}