-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIDA_Source_Codes.R
276 lines (224 loc) · 9 KB
/
MIDA_Source_Codes.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#https://github.com/BerkeKaragoz/Media-Investments-Data-Analysis
#
# CTIS 365 Data Analysis Term Project Source Codes
#
# E. Berke Karagoz & Sinan Isik
#
# Graph Source Codes
#
####################################################################
#
# MI_Distribution_TR
# 2010 - 2018 Media Investments Distribution of Turkey by Medium
#
####
rd <- read.csv(file = "ReklamcilarDernegi_YearlyInvestments.csv")
rdRaw <- rd
rdRaw$Years <- NULL
rdRaw
rdOneDimension <- c(rdRaw$TV, rdRaw$Press, rdRaw$Outdoor, rdRaw$Radio, rdRaw$Cinema, rdRaw$Digital)
rdOneDimension
specie <- rep(2018:2010, 6)
specie
Medium <- c(rep("TV", 9), rep("Press", 9),rep("Outdoor", 9),rep("Radio", 9),rep("Cinema", 9), rep("Digital", 9))
Medium
data <- data.frame(specie, Medium, rdOneDimension)
library(ggplot2)
cls <- rep(c("blue", "cyan", "red", "green", "black", "orange"), 9);
ggplot(data, aes(fill=Medium, y=rdOneDimension, x=specie)) +
geom_bar(position="fill", stat="identity") +
ggtitle("2010 - 2018 Media Investments Distribution of Turkey by Medium", subtitle = "According to Data from Reklamcilar Dernegi") +
xlab("Years") + ylab("Distribution") +
scale_x_continuous(breaks=specie) +
scale_fill_manual(values=cls) + theme_void() +
theme(
plot.title = element_text(hjust = 0.5, size = 14), # Center title position and size
plot.subtitle = element_text(hjust = 0.5), # Center subtitle
plot.caption = element_text(hjust = 0, face = "italic"),# move caption to the left
legend.position = "bottom"
)
###
#
# IUP_TR_vs_USA_2019
# 2019 Estimates of Internet Usage and Population for TR and USA
#
###
usaInt <- read.csv(file="usaInternet.csv", header=T)
usaInt
trInt <- read.csv(file="trInternet.csv", header=T)
trInt
usaInt$Population.Penetration <- trInt$Population.Penetration <- NULL
internet <- rbind(usaInt, trInt)
internet
value <- c(internet$Population, internet$Internet.Usage, internet$Facebook)
condition <- c(rep("Population", 2), rep("Internet Users", 2), rep("Facebook",2) )
specie <- rep(c("USA", "TR"), 3)
data <- data.frame(specie, condition, value)
cls <- rep(c("#3b5998", "cyan", "yellow"), 2);
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar(position="dodge", stat="identity") +
ggtitle("2019 Estimates of Internet Usage and Population for TR and USA") +
xlab("Countries") + ylab("Million") + scale_fill_manual(values = cls) + labs(fill="") +
ggtitle("Turkey Media Investments by Medium in 2010") +
theme(
plot.title = element_text(hjust = 0.5, size = 14), # Center title position and size
plot.subtitle = element_text(hjust = 0.5), # Center subtitle
plot.caption = element_text(hjust = 0, face = "italic")# move caption to the left
)
###
#
# MI_Digital_vs_Traditional_TR
# 2010 - 2018 Digital vs Traditional Investments of Turkey
#
###
rdYear <- read.csv("ReklamcilarDernegi_YearlyInvestments.csv")
rdFrame <- data.frame(rdYear)
traditional <- rowSums(rdFrame[, c(2,3,4,5,6)])
digital <- rdFrame$Digital
rdFrame
rd.years <- c("2018", "2017", "2016", "2015", "2014", "2013", "2012", "2011", "2010")
specie <- c(rep(rd.years[1], 2) , rep(rd.years[2] , 2) , rep(rd.years[3] , 2) , rep(rd.years[4] , 2), rep(rd.years[5] , 2), rep(rd.years[6] , 2),
rep(rd.years[7] , 2), rep(rd.years[8] , 2), rep(rd.years[9] , 2))
Type <- rep(c("Traditional" , "Digital"), 9)
value <- c(traditional[1], digital[1], traditional[2], digital[2], traditional[3], digital[3]
,traditional[4], digital[4], traditional[5], digital[5], traditional[6], digital[6],
traditional[7], digital[7], traditional[8], digital[8], traditional[9], digital[9])
data <- data.frame(specie,Type,value)
# Stacked
ggplot(data, aes(fill=Type, y=value, x=specie)) +
geom_bar(position="stack", stat="identity") + ggtitle("2010 - 2018 Digital vs Traditional Investments of Turkey", subtitle = "According to Data from Reklamcilar Dernegi") +
xlab("Years") + ylab("Thousand TL") + theme(plot.title = element_text(hjust = -0.5)) + theme_bw() +
theme(
plot.title = element_text(hjust = 0.5, size = 14), # Center title position and size
plot.subtitle = element_text(hjust = 0.5), # Center subtitle
plot.caption = element_text(hjust = 0, face = "italic")# move caption to the left
)
###
#
# MI_TR_vs_USA_Digital
# TR vs the USA Digital Media Advertisement Expenditures
#
###
# library
library(ggplot2)
# create a dataset
specie <- c(rep("Search Engine", 2) , rep("Banner", 2), rep("Video", 2), rep("Other", 2))
condition <- rep(c("USA", "TR") , 4)
tr <- read.csv("trExpenditures.csv", header=T)
tr$Year <- NULL
trMean <- colMeans(tr)
trMean
trVector <- as.numeric(trMean)
trVector
usa <- read.csv("usaExpenditures.csv", header=T)
usa$Year <- NULL
usaMean <- colMeans(usa)
usaMean
usaVector <- as.numeric(usaMean)
usaVector
value <- c(usaVector[1], trVector[1],usaVector[2], trVector[2],usaVector[3], trVector[3],usaVector[4], trVector[4])
value
data <- data.frame(specie,condition,value)
# Grouped
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar(position="dodge", stat="identity") + scale_y_log10() +
scale_fill_manual("Countries", values= c("USA" = "#3C3B6E", "TR" = "red"))+
theme_bw() +
theme(
plot.title = element_text(hjust = 0.5, size = 14), # Center title position and size
plot.subtitle = element_text(hjust = 0.5), # Center subtitle
plot.caption = element_text(hjust = 0, face = "italic")# move caption to the left
) +
ggtitle("TR vs the USA Digital Media Advertisement Expenditures", subtitle = "According to 2017 and 2018 First Halves Means Recompiled Data from IAB as Log Values") + xlab("Medium") + ylab("Million $")
###
#
# MI_TR_Medium_2010
# Donut Medium 2010
#
###
data <- data.frame(
Category=c("TV", "Press", "Outdoor", "Cinema", "Digital", "Radio"),
count=c(rdFrame$TV[9], rdFrame$Press[9], rdFrame$Outdoor[9], rdFrame$Cinema[9], rdFrame$Digital[9] , rdFrame$Radio[9])
)
# Compute percentages
data$fraction = data$count / sum(data$count)
# Compute the cumulative percentages (top of each rectangle)
data$ymax = cumsum(data$fraction)
# Compute the bottom of each rectangle
data$ymin <- c(0, head(data$ymax, n=-1))
# Compute label position
data$labelPosition <- (data$ymax + data$ymin) / 2
# Compute a good label
data$label <- paste0(data$category, "\n value: ", data$count)
# Compute the bottom of each rectangle
data$ymin = c(0, head(data$ymax, n=-1))
data$pct <- round(data$fraction*100)
data$pct <- paste(data$pct,"%",sep="") # add % to labels
# Make the plot
ggplot(data, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=Category)) +
geom_rect()+
geom_text( x=3.5, aes(y = labelPosition, label = data$pct), color = "white")+
coord_polar(theta="y") + # Try to remove that to understand how the chart is built initially
xlim(c(2, 4))+ # Try to remove that to see how to make a pie chart
theme_void() +
ggtitle("Turkey Media Investments by Medium in 2010") +
theme(
plot.title = element_text(hjust = 0.5, size = 14, vjust = -12.5), # Center title position and size
plot.subtitle = element_text(hjust = 0.5), # Center subtitle
plot.caption = element_text(hjust = 0, face = "italic"),# move caption to the left
legend.position = c(0.5, 0.5)
)
###
#
# MI_TR_Medium_2018
# Donut Medium 2018
#
###
data <- data.frame(
Category=c("TV", "Press", "Outdoor", "Cinema", "Digital", "Radio"),
count=c(rdFrame$TV[1], rdFrame$Press[1], rdFrame$Outdoor[1], rdFrame$Cinema[1], rdFrame$Digital[1] , rdFrame$Radio[1])
)
# Compute percentages
data$fraction = data$count / sum(data$count)
# Compute the cumulative percentages (top of each rectangle)
data$ymax = cumsum(data$fraction)
# Compute the bottom of each rectangle
data$ymin <- c(0, head(data$ymax, n=-1))
# Compute label position
data$labelPosition <- (data$ymax + data$ymin) / 2
# Compute a good label
data$label <- paste0(data$category, "\n value: ", data$count)
# Compute the bottom of each rectangle
data$ymin = c(0, head(data$ymax, n=-1))
data$pct <- round(data$fraction*100)
data$pct <- paste(data$pct,"%",sep="") # add % to labels
# Make the plot
ggplot(data, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=Category)) +
geom_rect()+
geom_text( x=3.5, aes(y = labelPosition, label = data$pct), color = "white")+
coord_polar(theta="y") + # Try to remove that to understand how the chart is built initially
xlim(c(2, 4))+ # Try to remove that to see how to make a pie chart
theme_void() +
ggtitle("Turkey Media Investments by Medium in 2018") +
theme(
plot.title = element_text(hjust = 0.5, size = 14, vjust = -12.5), # Center title position and size
plot.subtitle = element_text(hjust = 0.5), # Center subtitle
plot.caption = element_text(hjust = 0, face = "italic"),# move caption to the left
legend.position = c(0.5, 0.5)
)
###
#
###################################################################
#
# These codes are used for descriptive stats:
#
###
library(Hmisc)
rd <- read.csv("rd2.csv", header=T)
rd$Years <- NULL
summary(rd)
DS <- describe(rd)
DS
round(sd(rd$Digital),2)
describe(rd)
### E. Berke Karagoz and Sinan Isik