-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.qmd
More file actions
299 lines (255 loc) · 8.64 KB
/
statistics.qmd
File metadata and controls
299 lines (255 loc) · 8.64 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
---
title: "Research Statistics"
format: html
execute:
warning: false
message: false
---
```{r}
#| label: setup
#| echo: false
library(cranlogs)
library(scholar)
library(plotly)
library(dplyr)
library(htmltools)
# ---- Cohesive color palette (warm academic tones) ----
col_dark <- "#1b2a4a"
col_blue <- "#3a6ea5"
col_teal <- "#28a99e"
col_orange <- "#e8843c"
col_rose <- "#c74b7a"
col_gray <- "#5a6d7e"
col_purple <- "#7b5ea7"
# Chart colors
chart_colors <- c(col_dark, col_teal, col_orange, col_blue, col_rose, col_gray, col_purple)
# ---- Google Scholar data (with local cache) ----
scholar_id <- "Qu66YZQAAAAJ"
cache_file <- "scholar_cache.json"
profile <- tryCatch({
p <- get_profile(scholar_id)
if (is.list(p) && "total_cites" %in% names(p)) p else stop("invalid")
}, error = function(e) NULL)
cite_history <- tryCatch({
ch <- get_citation_history(scholar_id)
if (is.data.frame(ch) && nrow(ch) > 0) ch else stop("invalid")
}, error = function(e) NULL)
# If Scholar API succeeded, save cache for CI use
if (!is.null(profile) && !is.null(cite_history)) {
jsonlite::write_json(
list(profile = profile, cite_history = cite_history),
cache_file, auto_unbox = TRUE, pretty = TRUE
)
}
# If Scholar API failed, load from cache
if (is.null(profile) || is.null(cite_history)) {
if (file.exists(cache_file)) {
cache <- jsonlite::read_json(cache_file, simplifyVector = TRUE)
if (is.null(profile)) profile <- cache$profile
if (is.null(cite_history)) cite_history <- as.data.frame(cache$cite_history)
}
}
```
## Google Scholar Metrics
```{r}
#| label: scholar-metrics
#| echo: false
if (!is.null(profile)) {
total_cites <- profile$total_cites
h_index <- profile$h_index
i10_index <- profile$i10_index
} else {
total_cites <- "N/A"
h_index <- "N/A"
i10_index <- "N/A"
}
make_card <- function(value, label, bg_color) {
div(
style = paste0(
"background:", bg_color, ";padding:1.5rem 2.5rem;",
"border-radius:12px;text-align:center;min-width:180px;",
"box-shadow:0 4px 12px rgba(0,0,0,0.15);"
),
h1(style = "margin:0;font-size:2.5rem;font-weight:700;color:#ffffff;", value),
tags$hr(style = "border:0;border-top:1px solid rgba(255,255,255,0.3);margin:0.5rem 1rem;"),
p(style = "margin:0;color:rgba(255,255,255,0.9);font-size:0.95rem;", label)
)
}
div(
style = "display:flex;justify-content:center;gap:2rem;flex-wrap:wrap;margin:1.5rem 0;",
make_card(format(total_cites, big.mark = ","), "Total Citations", col_dark),
make_card(h_index, "H-Index", col_blue),
make_card(i10_index, "i10-Index", col_teal)
)
```
### Citations per Year
```{r}
#| label: citations-per-year
#| echo: false
if (!is.null(cite_history)) {
plot_ly(cite_history, x = ~year, y = ~cites, type = "bar",
marker = list(color = col_teal),
hovertemplate = "Year: %{x}<br>Citations: %{y:,}<extra></extra>") |>
layout(
xaxis = list(title = "Year", dtick = 1),
yaxis = list(title = "Citations"),
plot_bgcolor = "rgba(0,0,0,0)",
paper_bgcolor = "rgba(0,0,0,0)",
margin = list(t = 10, l = 60, r = 20, b = 50)
)
} else {
cat("Citation history currently unavailable.")
}
```
### Cumulative Citations
```{r}
#| label: cumulative-citations
#| echo: false
if (!is.null(cite_history)) {
cite_history$cumulative <- cumsum(cite_history$cites)
plot_ly(cite_history, x = ~year, y = ~cumulative, type = "scatter", mode = "lines+markers",
line = list(color = col_dark, width = 3),
marker = list(color = col_dark, size = 7),
hovertemplate = "Year: %{x}<br>Cumulative: %{y:,}<extra></extra>") |>
layout(
xaxis = list(title = "Year", dtick = 2),
yaxis = list(title = "Cumulative Citations"),
plot_bgcolor = "rgba(0,0,0,0)",
paper_bgcolor = "rgba(0,0,0,0)",
margin = list(t = 10, l = 60, r = 20, b = 50)
)
} else {
cat("Citation history currently unavailable.")
}
```
---
## CRAN Package Downloads
```{r}
#| label: cran-downloads
#| echo: false
my_packages <- c("bibliometrix", "openalexR", "dimensionsR", "pubmedR", "e2tree", "contentanalysis", "tall")
totals <- lapply(my_packages, function(pkg) {
tryCatch({
dl <- cran_downloads(pkg, from = "2015-01-01", to = Sys.Date())
data.frame(package = pkg, total = sum(dl$count, na.rm = TRUE))
}, error = function(e) {
data.frame(package = pkg, total = 0)
})
})
totals_df <- bind_rows(totals) |> arrange(desc(total))
```
### Total CRAN Downloads
```{r}
#| label: download-cards
#| echo: false
card_colors <- c(col_dark, col_blue, col_teal, col_orange, col_rose, col_gray, col_purple)
make_dl_card <- function(value, label, bg_color) {
div(
style = paste0(
"background:", bg_color, ";padding:0.8rem 1rem;",
"border-radius:10px;text-align:center;",
"box-shadow:0 4px 12px rgba(0,0,0,0.15);"
),
h3(style = "margin:0;font-weight:700;color:#ffffff;font-size:1.3rem;", value),
tags$hr(style = "border:0;border-top:1px solid rgba(255,255,255,0.3);margin:0.4rem 0.8rem;"),
p(style = "margin:0;color:rgba(255,255,255,0.9);font-size:0.8rem;", label)
)
}
cards <- lapply(seq_len(nrow(totals_df)), function(i) {
bg <- card_colors[((i - 1) %% length(card_colors)) + 1]
make_dl_card(format(totals_df$total[i], big.mark = ","), totals_df$package[i], bg)
})
div(
style = "max-width:850px;margin:1.5rem auto;",
div(
style = "display:grid;grid-template-columns:repeat(4,1fr);gap:1rem;margin-bottom:1rem;",
tagList(cards[1:min(4, length(cards))])
),
div(
style = "display:grid;grid-template-columns:repeat(3,1fr);gap:1rem;max-width:637px;margin:0 auto;",
tagList(cards[5:length(cards)])
)
)
```
### Cumulative Downloads Over Time
```{r}
#| label: cumulative-downloads
#| echo: false
monthly_data <- lapply(seq_along(my_packages), function(i) {
pkg <- my_packages[i]
tryCatch({
dl <- cran_downloads(pkg, from = "2015-01-01", to = Sys.Date())
dl$month <- format(dl$date, "%Y-%m")
monthly <- dl |> group_by(month) |> summarise(downloads = sum(count), .groups = "drop")
monthly$cumulative <- cumsum(monthly$downloads)
monthly$package <- pkg
monthly$date <- as.Date(paste0(monthly$month, "-01"))
monthly
}, error = function(e) NULL)
})
monthly_all <- bind_rows(monthly_data)
if (nrow(monthly_all) > 0) {
p <- plot_ly()
for (i in seq_along(unique(monthly_all$package))) {
pkg <- unique(monthly_all$package)[i]
d <- monthly_all |> filter(package == pkg)
col <- chart_colors[((i - 1) %% length(chart_colors)) + 1]
p <- p |> add_trace(data = d, x = ~date, y = ~cumulative,
type = "scatter", mode = "lines",
name = pkg,
line = list(width = 2.5, color = col),
hovertemplate = paste0(pkg, "<br>%{x|%b %Y}<br>Cumulative: %{y:,}<extra></extra>"))
}
p |> layout(
xaxis = list(title = "Date"),
yaxis = list(title = "Cumulative Downloads"),
legend = list(orientation = "h", x = 0.5, xanchor = "center", y = -0.15),
plot_bgcolor = "rgba(0,0,0,0)",
paper_bgcolor = "rgba(0,0,0,0)",
margin = list(t = 10, l = 60, r = 20, b = 70)
)
}
```
### Monthly Downloads (Last 12 Months)
```{r}
#| label: monthly-downloads-recent
#| echo: false
recent_data <- lapply(seq_along(my_packages), function(i) {
pkg <- my_packages[i]
tryCatch({
dl <- cran_downloads(pkg, from = Sys.Date() - 365, to = Sys.Date())
dl$month <- format(dl$date, "%Y-%m")
monthly <- dl |> group_by(month) |> summarise(downloads = sum(count), .groups = "drop")
monthly$package <- pkg
monthly$date <- as.Date(paste0(monthly$month, "-01"))
monthly
}, error = function(e) NULL)
})
recent_all <- bind_rows(recent_data)
if (nrow(recent_all) > 0) {
p <- plot_ly()
for (i in seq_along(my_packages)) {
pkg <- my_packages[i]
d <- recent_all |> filter(package == pkg)
col <- chart_colors[((i - 1) %% length(chart_colors)) + 1]
p <- p |> add_trace(data = d, x = ~date, y = ~downloads,
type = "bar", name = pkg,
marker = list(color = col),
hovertemplate = paste0(pkg, "<br>%{x|%b %Y}<br>Downloads: %{y:,}<extra></extra>"))
}
p |> layout(
barmode = "group",
xaxis = list(title = "Month"),
yaxis = list(title = "Downloads"),
legend = list(orientation = "h", x = 0.5, xanchor = "center", y = -0.15),
plot_bgcolor = "rgba(0,0,0,0)",
paper_bgcolor = "rgba(0,0,0,0)",
margin = list(t = 10, l = 60, r = 20, b = 70)
)
}
```
---
<p style="text-align: center; color: #8899a6; font-size: 0.85rem; margin-top: 2rem;">
Data updated automatically each time the site is rendered.<br>
Citations source: Google Scholar. Downloads source: CRAN logs.
</p>