-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcartograms.R
172 lines (102 loc) · 5.16 KB
/
cartograms.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
library(tidyverse)
library(cartogram)
library(maptools)
data(wrld_simpl)
road <- read_xlsx("road_data_merged.xlsx")
prepcarto <- road %>%
group_by(iso3_code) %>%
summarise(across(starts_with("in"), sum))
prepcarto$n <- prepcarto$n*10
wrld_simpl@data$scopus <- prepcarto$in_scopus[match(wrld_simpl@data$ISO3, prepcarto$iso3_code)]
wrld_simpl@data$wos <- prepcarto$in_wos[match(wrld_simpl@data$ISO3, prepcarto$iso3_code)]
wrld_simpl@data$doaj <- prepcarto$in_doaj[match(wrld_simpl@data$ISO3, prepcarto$iso3_code)]
wrld_simpl@data$sherpa <- prepcarto$in_sherpa[match(wrld_simpl@data$ISO3, prepcarto$iso3_code)]
wrld_simpl@data$openalex <- prepcarto$in_openalex[match(wrld_simpl@data$ISO3, prepcarto$iso3_code)]
wrld_simpl@data$topfactor <- prepcarto$in_top_factor[match(wrld_simpl@data$ISO3, prepcarto$iso3_code)]
replace_na_by_zero <- function(x) {
ifelse(is.na(x), 0, x)
}
wrld_simpl@data$scopus <- replace_na_by_zero(wrld_simpl@data$scopus)
wrld_simpl@data$wos <- replace_na_by_zero(wrld_simpl@data$wos)
wrld_simpl@data$doaj <- replace_na_by_zero(wrld_simpl@data$doaj)
wrld_simpl@data$sherpa <- replace_na_by_zero(wrld_simpl@data$sherpa)
wrld_simpl@data$openalex <- replace_na_by_zero(wrld_simpl@data$openalex)
wrld_simpl@data$topfactor <- replace_na_by_zero(wrld_simpl@data$topfactor)
wrld_simpl <- spTransform(wrld_simpl[wrld_simpl$scopus > 0,], "+proj=moll") # if spTransform does not work, use sf::st_transform
wrld_dorling <- cartogram_dorling(wrld_simpl, "scopus", m_weight = 0.3)
colrs <- RColorBrewer::brewer.pal(3, "Set2")
svg(paste("plots/cartograms/cartogram_scopus.svg"), width = 8, height = 6)
plot.new()
plot(wrld_dorling, col= "blue", border ="white", bg = "white")
cartography::layoutLayer(title = "Scopus",
sources = "", north = TRUE, tabtitle = TRUE,
theme = "black.pal", frame = TRUE,
author = "ROAD")
cartography::labelLayer(x = wrld_dorling, txt = "ISO2", overlap = FALSE, show.lines = FALSE,
halo = TRUE, r = .15)
dev.off()
######
wrld_dorling <- cartogram_dorling(wrld_simpl, "wos", m_weight = 0.3)
colrs <- RColorBrewer::brewer.pal(3, "Set2")
svg(paste("plots/cartograms/cartogram_wos.svg"), width = 8, height = 6)
plot.new()
plot(wrld_dorling, col= "blue", border ="white", bg = "white")
cartography::layoutLayer(title = "WoS",
sources = "", north = TRUE, tabtitle = TRUE,
theme = "black.pal", frame = TRUE,
author = "ROAD")
cartography::labelLayer(x = wrld_dorling, txt = "ISO2", overlap = FALSE, show.lines = FALSE,
halo = TRUE, r = .15)
dev.off()
######
wrld_dorling <- cartogram_dorling(wrld_simpl, "openalex", m_weight = 0.3)
colrs <- RColorBrewer::brewer.pal(3, "Set2")
svg(paste("plots/cartograms/cartogram_openalex.svg"), width = 8, height = 6)
plot.new()
plot(wrld_dorling, col= "blue", border ="white", bg = "white")
cartography::layoutLayer(title = "OpenAlex",
sources = "", north = TRUE, tabtitle = TRUE,
theme = "black.pal", frame = TRUE,
author = "ROAD")
cartography::labelLayer(x = wrld_dorling, txt = "ISO2", overlap = FALSE, show.lines = FALSE,
halo = TRUE, r = .15)
dev.off()
######
wrld_dorling <- cartogram_dorling(wrld_simpl, "doaj", m_weight = 0.3)
colrs <- RColorBrewer::brewer.pal(3, "Set2")
svg(paste("plots/cartograms/cartogram_doaj.svg"), width = 8, height = 6)
plot.new()
plot(wrld_dorling, col= "blue", border ="white", bg = "white")
cartography::layoutLayer(title = "DOAJ",
sources = "", north = TRUE, tabtitle = TRUE,
theme = "black.pal", frame = TRUE,
author = "ROAD")
cartography::labelLayer(x = wrld_dorling, txt = "ISO2", overlap = FALSE, show.lines = FALSE,
halo = TRUE, r = .15)
dev.off()
######
wrld_dorling <- cartogram_dorling(wrld_simpl, "sherpa", m_weight = 0.3)
colrs <- RColorBrewer::brewer.pal(3, "Set2")
svg(paste("plots/cartograms/cartogram_sherpa.svg"), width = 8, height = 6)
plot.new()
plot(wrld_dorling, col= "blue", border ="white", bg = "white")
cartography::layoutLayer(title = "Sherpa",
sources = "", north = TRUE, tabtitle = TRUE,
theme = "black.pal", frame = TRUE,
author = "ROAD")
cartography::labelLayer(x = wrld_dorling, txt = "ISO2", overlap = FALSE, show.lines = FALSE,
halo = TRUE, r = .15)
dev.off()
######
wrld_dorling <- cartogram_dorling(wrld_simpl, "topfactor", m_weight = 0.3)
colrs <- RColorBrewer::brewer.pal(3, "Set2")
svg(paste("plots/cartograms/cartogram_topfactor.svg"), width = 8, height = 6)
plot.new()
plot(wrld_dorling, col= "blue", border ="white", bg = "white")
cartography::layoutLayer(title = "Top Factor",
sources = "", north = TRUE, tabtitle = TRUE,
theme = "black.pal", frame = TRUE,
author = "ROAD")
cartography::labelLayer(x = wrld_dorling, txt = "ISO2", overlap = FALSE, show.lines = FALSE,
halo = TRUE, r = .15)
dev.off()