-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScholar_plot-trial_file.R
215 lines (180 loc) · 8.66 KB
/
Scholar_plot-trial_file.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
#list of packages required
list.of.packages <- c("tidyverse", "scholar", "NLP", "RColorBrewer", "tm", "wordcloud", "qdap", "readtext", "xml2", "rvest")
#checking missing packages from list
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
#install missing ones
if(length(new.packages)) install.packages(new.packages, dependencies = TRUE)
### Load packages
for (i in list.of.packages) {
print(i)
library(i, character.only = TRUE)
}
# APCAH Staff
# Alistair Legione Scholar ID: OmIonF8AAAAJ
# Mauricio Coppo: pPYRgUAAAAAJ
# Nadeeka Wawegama: iiDz-skAAAAJ
# Joanne Devlin: b_0bnnoAAAAJ
# Paola Vaz: 4bkOEhEAAAAJ
# Glenn Browning: jg0S8-wAAAAJ
# Simon Firestone: z9_YatsAAAAJ
id <- "rW9T5f4AAAAJ"
nToday <- yday(Sys.time())
ct <- get_citation_history(id)
ct$citesPerMonth <- ct$cites/12
finalRow <- nrow(ct)
ct$citesPerMonth[finalRow] <- ct$cites[finalRow]/7
ct$citesPerYear <- ct$cites
ct$citesPerYear[finalRow] <- ct$citesPerYear[finalRow]/nToday * 365
ct
# ct <- rbind(c(2006,0,0,0), ct)
p <- get_publications(id)
p <- p[complete.cases(p$year),]
#ct <- ct[1:13,1:4]
p
papersPerYear <- as.data.frame(x = table(p$year),
stringsAsFactors = FALSE
)
papersPerYear <- rename(papersPerYear, "year" = "Var1")
papersPerYear$year <- as.numeric(as.character(papersPerYear$year))
ct <- full_join(x = ct, y = papersPerYear, by = c("year"))
ct <- arrange(ct, year)
ct[is.na(ct)] <- 0
ct$sum <- cumsum(ct$Freq)
papersPerYear
#rbind(papersPerYear, c(as.factor(2019),0,81))
# ct$papersPerYear <- papersPerYear$Freq
#ct$papersPerYear <- papersPerYear$Freq[2:9]
ct
ctMinus <- ct[1:nrow(ct)-1,] #saves citations less the current year to remove small values
transform <- round(x =max(ct$cites)/max(ct$Freq) * (2/3), digits = 0)
(citationsPlot <- ggplot(data = ct) +
geom_col(aes(x = year, y = Freq * transform), fill = "White", colour = "black", size = 1) +
# geom_line(aes(x = year, y = citesPerYear), size = 2, colour = "Purple", linetype = 2) +
geom_line(aes(x = year, y = cites), size = 2, colour = "Grey") +
geom_point(aes(x = year, y = cites), size = 4, colour = "Black") +
# geom_point(aes(x = year, y = citesPerYear), size = 4, colour = "Black") +
ylab("Annual Citations") +
# ggtitle("Dr Alistair Legione") +
xlab("Year") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 15)) +
theme(legend.title = element_text(face = "bold", size = 15)) +
theme(legend.text = element_text(size = 14)) +
theme(axis.title.x = element_text(face = "bold", size = 15, colour = "Black"),
axis.text.x = element_text(face = "bold", size = 12, colour = "Black")) +
theme(axis.title.y = element_text(face = "bold",
size = 15, colour = "Black",
margin = margin(t = 0, r = 10, b = 0, l = 10)),
axis.title.y.right = element_text(margin = margin(t = 0, r = 10, b = 0, l = 10)),
axis.text.y = element_text(face = "bold", size = 12, colour = "Black")) +
scale_y_continuous(sec.axis = sec_axis(trans = ~. / transform, name = "Annual Papers")) +
#scale_colour_manual("", breaks = c("Citations_per_year", "Projected_citations"), values = c("Citations_per_year" = "Cyan", "Projected_citations" = "Purple")) +
NULL
)
(citationsPlot <- ggplot(data = ct) +
geom_col(aes(x = year, y = Freq * transform), fill = "White", colour = "black", size = 1) +
# geom_line(aes(x = year, y = citesPerYear), size = 2, colour = "Purple", linetype = 2) +
geom_line(aes(x = year, y = cites), size = 2, colour = "Grey") +
geom_point(aes(x = year, y = cites), size = 4, colour = "Black") +
# geom_point(aes(x = year, y = citesPerYear), size = 4, colour = "Black") +
ylab("Annual Citations") +
# ggtitle("Dr Alistair Legione") +
xlab("Year") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 15)) +
theme(legend.title = element_text(face = "bold", size = 15)) +
theme(legend.text = element_text(size = 14)) +
theme(axis.title.x = element_text(face = "bold", size = 15, colour = "Black"),
axis.text.x = element_text(face = "bold", size = 12, colour = "Black", angle = 90, vjust = 0.5)) +
theme(axis.title.y = element_text(face = "bold",
size = 15, colour = "Black",
margin = margin(t = 0, r = 10, b = 0, l = 10)),
axis.title.y.right = element_text(margin = margin(t = 0, r = 10, b = 0, l = 10)),
axis.text.y = element_text(face = "bold", size = 12, colour = "Black")) +
scale_x_continuous(breaks = c(seq(from = min(ct$year), to = max(ct$year, by = 1)))) +
scale_y_continuous(sec.axis = sec_axis(trans = ~. / transform, name = "Annual Papers")) +
#scale_colour_manual("", breaks = c("Citations_per_year", "Projected_citations"), values = c("Citations_per_year" = "Cyan", "Projected_citations" = "Purple")) +
NULL
)
ggplot(ct, aes(year, citesPerMonth)) + geom_line() + geom_point()
p <- get_publications(id)
p$ImpactFactor <- get_impactfactor(p$journal, max.distance = 0.20)$ImpactFactor
p$citesPerYear <- p$cites/(2019-p$year+1)
p$PaperScore <- p$citesPerYear+p$ImpactFactor
CiteTable <- filter(p, PaperScore > 0) %>% arrange(desc(PaperScore)) %>% select(-cid, -pubid)
CumulativeImpact <- sum(CiteTable$ImpactFactor)
papersPerYear <- as.data.frame(table((p$year)))
papersPerYear$sum <- cumsum(papersPerYear[,2])
papersPerYear
ct$papersPerYear <- papersPerYear$Freq
#ct$papersPerYear <- papersPerYear$Freq[2:9]
ctMinus <- ct[1:nrow(ct)-1,] #saves citations less the current year to remove small values
(citationsPlotMinus <- ggplot(ctMinus) +
geom_col(aes(x = year, y = papersPerYear*20), fill = "White", colour = "black", size = 1) +
# geom_line(aes(x = year, y = citesPerYear), size = 2, colour = "Purple", linetype = 2) +
geom_line(aes(x = year, y = cites), size = 2, colour = "Grey") +
geom_point(aes(x = year, y = cites), size = 4, colour = "Black") +
# geom_point(aes(x = year, y = citesPerYear), size = 4, colour = "Black") +
ylab("Annual Citations") +
#ggtitle("Citation metrics") +
xlab("Year") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 15)) +
theme(legend.title = element_text(face = "bold", size = 15)) +
theme(legend.text = element_text(size = 14)) +
theme(axis.title.x = element_text(face = "bold",
size = 15, colour = "Black"),
axis.text.x = element_text(face = "bold",
size = 12,
colour = "Black")) +
theme(axis.title.y = element_text(face = "bold",
size = 15,
colour = "Black",
margin = margin(t = 0, r = 10, b = 0, l = 10)),
axis.text.y = element_text(face = "bold",
size = 12,
colour = "Black"),
axis.title.y.right = element_text(margin = margin(t = 0, r = 10, b = 0, l = 10))) +
#scale_colour_manual("", breaks = c("Citations_per_year", "Projected_citations"), values = c("Citations_per_year" = "Cyan", "Projected_citations" = "Purple")) +
scale_y_continuous(sec.axis = sec_axis(trans = ~./20, name = "Annual Papers")) +
NULL
)
ggplot() +
geom_col(data = papersPerYear, aes(x = Var1, y = Freq), fill = "Navy") +
NULL
#loop below, to produce a graph for every file, not working
for (i in 1:nrow(p)) {
ach <- get_article_cite_history(id, p$pubid[i])
ggplot(ach, aes(year, cites)) +
geom_segment(aes(xend = year, yend = 0), size=1, color='darkgrey') +
geom_point(size=3, color='firebrick') +
ggtitle(p$title[i])
}
# Below function to get abstracts from publications
get_abstract <- function(id, publication) {
abstract <- ""
url_template <- "http://scholar.google.com/citations?view_op=view_citation&citation_for_view=%s:%s"
url <- sprintf(url_template, id, publication)
url1 <- get_scholar_resp(url) %>%
read_html
abstract <- as.character(rvest::html_node(url1,".gsh_csp") %>% rvest::html_text())
return(abstract)
}
concat_abstract <- function(id, publication, text){
textnew <- cat(text, get_abstract(id = id, publication = publication))
}
Generate_WordCloud <- reactive({
p <- get_publications(id = id)
remove(text1)
text1 <- NULL
for (i in p$pubid) {
abstract_tmp <- get_abstract(id = id, publication = i)
Sys.sleep(1)
if (is.null(text1)) {
text1 <- abstract_tmp
} else {
text1 <- cat(text1, abstract_tmp)
}
}
lapply(id, p$pubid, concat_abstract)
})