-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_Amnesty_International_search_maps.R
272 lines (217 loc) · 11.4 KB
/
google_Amnesty_International_search_maps.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
## google_Amnesty_International_search_maps.R
##########################################################################
##
## Authors: Geoff Dancy and Christopher J. Fariss
##
## Title: "The Search for Human Rights: A Global Analysis Using Google Data"
##
## Contact Information:
## Geoff Dancy <geoff.dancy@utoronto.ca>
## Christopher J. Fariss <cjf0006@gmail.com>
##
## Copyright (c) 2022, under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
## For more information see: http://creativecommons.org/licenses/by-nc-sa/3.0/us/
## All rights reserved.
##
##########################################################################
## load necessary libraries
## change groundhog to TRUE to install original versions of libraries from April-2022
source("groundhog_library_func.R")
groundhog_library_func(groundhog=FALSE, regular_install=FALSE)
pdf("Rplots/Maps_Amnesty_International_search.pdf", height=3, width=6)
TERMS <- c("human rights", "derechos humanos", "direitos humanos", "حقوق الانسان", "права человека", "hak asasi Manusia", "人权", "droits")
COLORS <- c("#ffffcc", "#a1dab4", "#41b6c4", "#2c7fb8", "#253494")
COLORS <- c("#f0f9e8", "#bae4bc", "#7bccc4", "#43a2ca", "#0868ac")
COLORS <- c("#ffffcc", "#a1dab4", "#41b6c4", "#2c7fb8", "#253494")
COLORS <- c("#feebe2", "#fbb4b9", "#f768a1", "#c51b8a", "#7a0177")
COLORS <- c("#ffffcc", "#c2e699", "#78c679", "#31a354", "#006837")
COLORS <- c("#ffffcc", "#a1dab4", "#41b6c4", "#2c7fb8", "#253494", "black")
COLORS <- c("#f0f9e8", "#bae4bc", "#7bccc4", "#43a2ca", "#0868ac", "black")
COLORS <- c("#ffffcc", "#a1dab4", "#41b6c4", "#2c7fb8", "#253494", "black")
COLORS <- c("#feebe2", "#fbb4b9", "#f768a1", "#c51b8a", "#7a0177", "black")
COLORS <- c("#ffffcc", "#c2e699", "#78c679", "#31a354", "#006837", "black")
#barplot(c(1,1,1,1,1), col=COLORS)
TIME <- "2015-01-01 2019-12-31"
## ------------------------------------------------------------ ##
## google Topic "amnesty international" (this is langauge agnostic)
english.world <- gtrends("%2Fm%2F012l0", time=TIME, low_search_volume=FALSE)
english.world <- subset(english.world$interest_by_country)
english.world$hits[english.world$hits=="<1"] <- .5
english.world$hits <- as.numeric(english.world$hits)
data <- english.world[,1:2]
names(data) <- c("region", "hits")
data$region[data$region=="Côte d’Ivoire"] <- "Ivory Coast"
data$region[data$region=="Congo - Kinshasa"] <- "Democratic Republic of the Congo"
data$region[data$region=="Congo - Brazzaville"] <- "Republic of Congo"
data$region[data$region=="United Kingdom"] <- "UK"
data$region[data$region=="United States"] <- "USA"
#data$hits[is.na(data$hits)]<-0
COLORS <- c("#f0f9e8", "#bae4bc", "#7bccc4", "#43a2ca", "#0868ac", "black")
map.world <- map_data("world")
ggplot(data, aes(map_id = region)) +
geom_map(aes(fill = hits), map = map.world) +
ggtitle(paste("Topic: '", "Amnesty International", "'", sep="")) +
xlab("Latitude") + ylab("Longitude") +
coord_map("rectangular", lat0=0, xlim=c(-180,180), ylim=c(-60, 90)) +
expand_limits(x = map.world$long, y = map.world$lat) + scale_fill_gradientn(colours=COLORS, na.value=grey(.875), guide = "colourbar")
## ------------------------------------------------------------ ##
## google English/French language "amnesty international"
english.world <- gtrends("Amnesty International", time=TIME, low_search_volume=FALSE)
english.world <- subset(english.world$interest_by_country)
english.world$hits[english.world$hits=="<1"] <- .5
english.world$hits <- as.numeric(english.world$hits)
data <- english.world[,1:2]
names(data) <- c("region", "hits")
data$region[data$region=="Côte d’Ivoire"] <- "Ivory Coast"
data$region[data$region=="Congo - Kinshasa"] <- "Democratic Republic of the Congo"
data$region[data$region=="Congo - Brazzaville"] <- "Republic of Congo"
data$region[data$region=="United Kingdom"] <- "UK"
data$region[data$region=="United States"] <- "USA"
#data$hits[is.na(data$hits)]<-0
COLORS <- c("#f0f9e8", "#bae4bc", "#7bccc4", "#43a2ca", "#0868ac", "black")
map.world <- map_data("world")
ggplot(data, aes(map_id = region)) +
geom_map(aes(fill = hits), map = map.world) +
ggtitle(paste("English/French Langugage: '", "Amnesty International", "'", sep="")) +
xlab("Latitude") + ylab("Longitude") +
coord_map("rectangular", lat0=0, xlim=c(-180,180), ylim=c(-60, 90)) +
expand_limits(x = map.world$long, y = map.world$lat) + scale_fill_gradientn(colours=COLORS, na.value=grey(.875), guide = "colourbar")
## ------------------------------------------------------------ ##
## google Spanish language "Amnistía Internacional"
espanish.world <- gtrends("Amnistía Internacional", time=TIME, low_search_volume=FALSE)
espanish.world <- subset(espanish.world$interest_by_country)
espanish.world$hits[espanish.world$hits=="<1"] <- .5
espanish.world$hits <- as.numeric(espanish.world$hits)
data <- espanish.world[,1:2]
names(data) <- c("region", "hits")
data$region[data$region=="Côte d’Ivoire"] <- "Ivory Coast"
data$region[data$region=="Congo - Kinshasa"] <- "Democratic Republic of the Congo"
data$region[data$region=="Congo - Brazzaville"] <- "Republic of Congo"
data$region[data$region=="United Kingdom"] <- "UK"
data$region[data$region=="United States"] <- "USA"
#data$hits[is.na(data$hits)]<-0
COLORS <- c("#feebe2", "#fbb4b9", "#f768a1", "#c51b8a", "#7a0177", "black")
map.world <- map_data("world")
ggplot(data, aes(map_id = region)) +
geom_map(aes(fill = hits), map = map.world) +
ggtitle(paste("Spanish Langugage: '", "Amnistía Internacional", "'", sep="")) +
xlab("Latitude") + ylab("Longitude") +
coord_map("rectangular", lat0=0, xlim=c(-180,180), ylim=c(-60, 90)) +
expand_limits(x = map.world$long, y = map.world$lat) + scale_fill_gradientn(colours=COLORS, na.value=grey(.875), guide = "colourbar")
## ------------------------------------------------------------ ##
## google Portuguese language "Anistia Internacional"
portuguese.world <- gtrends("Anistia Internacional", time=TIME, low_search_volume=FALSE)
portuguese.world <- subset(portuguese.world$interest_by_country)
portuguese.world$hits[portuguese.world$hits=="<1"] <- .5
portuguese.world$hits <- as.numeric(portuguese.world$hits)
data <- portuguese.world[,1:2]
names(data) <- c("region", "hits")
data$region[data$region=="Côte d’Ivoire"] <- "Ivory Coast"
data$region[data$region=="Congo - Kinshasa"] <- "Democratic Republic of the Congo"
data$region[data$region=="Congo - Brazzaville"] <- "Republic of Congo"
data$region[data$region=="United Kingdom"] <- "UK"
data$region[data$region=="United States"] <- "USA"
#data$hits[is.na(data$hits)]<-0
COLORS <- c("#feebe2", "#fbb4b9", "#f768a1", "#c51b8a", "#7a0177", "black")
map.world <- map_data("world")
ggplot(data, aes(map_id = region)) +
geom_map(aes(fill = hits), map = map.world) +
ggtitle(paste("Portuguese Langugage: '", "Anistia Internacional", "'", sep="")) +
xlab("Latitude") + ylab("Longitude") +
coord_map("rectangular", lat0=0, xlim=c(-180,180), ylim=c(-60, 90)) +
expand_limits(x = map.world$long, y = map.world$lat) + scale_fill_gradientn(colours=COLORS, na.value=grey(.875), guide = "colourbar")
## ------------------------------------------------------------ ##
## google Arabic language "منظمة العفو الدولية", laa
arabic.world <- gtrends("منظمة العفو الدولية", time=TIME, low_search_volume=FALSE)
arabic.world <- subset(arabic.world$interest_by_country)
arabic.world$hits[english.world$hits=="<1"] <- .5
arabic.world$hits <- as.numeric(arabic.world$hits)
data <- arabic.world[,1:2]
names(data) <- c("region", "hits")
data$region[data$region=="Côte d’Ivoire"] <- "Ivory Coast"
data$region[data$region=="Congo - Kinshasa"] <- "Democratic Republic of the Congo"
data$region[data$region=="Congo - Brazzaville"] <- "Republic of Congo"
data$region[data$region=="United Kingdom"] <- "UK"
data$region[data$region=="United States"] <- "USA"
#data$hits[is.na(data$hits)]<-0
COLORS <- c("#f1eef6", "#d7b5d8", "#df65b0", "#dd1c77", "#980043", "black")
map.world <- map_data("world")
ggplot(data, aes(map_id = region)) +
geom_map(aes(fill = hits), map = map.world) +
ggtitle(paste("Arabic Langugage: '", "Munazamat Aleafw Alduwalia", "'", sep="")) +
xlab("Latitude") + ylab("Longitude") +
coord_map("rectangular", lat0=0, xlim=c(-180,180), ylim=c(-60, 90)) +
expand_limits(x = map.world$long, y = map.world$lat) + scale_fill_gradientn(colours=COLORS, na.value=grey(.875), guide = "colourbar")
dev.off()
## ------------------------------------------------------------ ##
## English "human rights"
english.world <- gtrends("human rights", time=TIME, low_search_volume=FALSE)
english.world <- subset(english.world$interest_by_country)
english.world$hits[english.world$hits=="<1"] <- .5
english.world$hits <- as.numeric(english.world$hits)
data <- english.world[,1:2]
names(data) <- c("region", "hits")
dim(data)
## ------------------------------------------------------------ ##
## English "Amnesty International"
english.world <- gtrends("Amnesty International", time=TIME, low_search_volume=FALSE)
english.world <- subset(english.world$interest_by_country)
english.world$hits[english.world$hits=="<1"] <- .5
english.world$hits <- as.numeric(english.world$hits)
data2 <- english.world[,1:2]
names(data2) <- c("region", "hits")
dim(data2)
## search term by seerach term correlations
test <- merge(data, data2, by="region", all=T)
dim(test)
par(mfrow=c(1,1))
plot(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y, method="spearman")
test$hits.x[is.na(test$hits.x) & !is.na(test$hits.y)] <- 0
test$hits.y[is.na(test$hits.y) & !is.na(test$hits.x)] <- 0
plot(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y, method="spearman")
## archive datasets
## set today's date for saving files below
current_date <- as.Date(Sys.time())
current_date
## save data.frame
write.csv(test, paste("Data_output/Maps_Anesty_International_language_validation", current_date, ".csv", sep=""), row.names=FALSE)
## ------------------------------------------------------------ ##
## Topic "human rights"
english.world <- gtrends("%2Fm%2F03ll3", time=TIME, low_search_volume=FALSE)
english.world <- subset(english.world$interest_by_country)
english.world$hits[english.world$hits=="<1"] <- .5
english.world$hits <- as.numeric(english.world$hits)
data <- english.world[,1:2]
names(data) <- c("region", "hits")
dim(data)
## ------------------------------------------------------------ ##
## Topic "Amnesty International"
english.world <- gtrends("%2Fm%2F012l0", time=TIME, low_search_volume=FALSE)
english.world <- subset(english.world$interest_by_country)
english.world$hits[english.world$hits=="<1"] <- .5
english.world$hits <- as.numeric(english.world$hits)
data2 <- english.world[,1:2]
names(data2) <- c("region", "hits")
dim(data2)
## Topic by Topic correlations
test <- merge(data, data2, by="region", all=T)
dim(test)
par(mfrow=c(1,1))
plot(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y, method="spearman")
test$hits.x[is.na(test$hits.x) & !is.na(test$hits.y)] <- 0
test$hits.y[is.na(test$hits.y) & !is.na(test$hits.x)] <- 0
plot(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y)
cor.test(test$hits.x, test$hits.y, method="spearman")
## archive datasets
## set today's date for saving files below
current_date <- as.Date(Sys.time())
current_date
## save data.frame
write.csv(test, paste("Data_output/Maps_Anesty_International_topic_validation", current_date, ".csv", sep=""), row.names=FALSE)