-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcitation.R
executable file
·68 lines (50 loc) · 1.95 KB
/
citation.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
library(scholar)
library(jsonlite)
library(dplyr)
library(ggplot2)
library(ggstance)
library(ggimage)
library(ggtree)
library(extrafont)
loadfonts(device = "win")
theme_set(theme_get() + theme(text = element_text(family = 'Times New Roman')))
#Sys.setenv(http_proxy="http://127.0.0.1:43723")
id <- '8p3wQNwAAAAJ'
profile <- tryCatch(get_profile(id), error = function(e) return(NULL))
if (!is.null(profile)) {
profile$date <- Sys.Date()
cat(toJSON(profile), file ="profile.json")
}
cites <- tryCatch(get_citation_history(id), error = function(e) return(NULL))
if (is.null(cites)) {
cites <- tinyscholar::tinyscholar(id)$citation
profile = jsonlite::fromJSON("profile.json")
if (profile$total_cites < cites[1,2])
profile$total_cites <- cites[1,2]
cat(toJSON(profile), file ="profile.json")
cites <- cites[-1, ] # remove 'total' row
names(cites) <- c("year", "cites")
cites$year <- as.numeric(cites$year)
}
if (!is.null(cites)) {
cat(toJSON(cites), file = "citation.json")
}
cites <- fromJSON("citation.json")
cites <- slice(cites, tail(row_number(), 6))
cites$year <- factor(cites$year)
p <- ggplot(cites, aes(cites, year)) +
geom_barh(stat='identity', fill = "#96B56C") +
geom_text2(aes(label=cites, subset = cites > 1), hjust=1.1, size=2) +
labs(caption = "data from Google Scholar") +
scale_x_continuous(position="top") +
theme_minimal(base_size=10) + xlab(NULL) + ylab(NULL) +
theme(panel.grid.major.y = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_line(linetype="dashed"),
plot.caption=element_text(colour='grey30', size=7, vjust = 1)) +
theme_transparent()
ggsave(p, file = "citation.png", width=2, height=2, bg = "transparent")
## library(magick)
## p <- image_read("citation.png")
## p <- image_transparent(p, "white")
## image_write(p, path="citation.png")