In this post I explain how I generated my Google Scholar citations automatic plot generator. After following these steps, you are going to be able to generate automatically your own Google Scholar citations plot in a daily basis, which your personal website will load (automatically too) every time someone visits it.
What you need: OSX, crontab, R, DropBox
- You should use a Mac.
- crontab should already be installed by default in your machine. So, there is no need to install that.
- You should have both a DropBox and a Google Scholar account.
- R should be updated.
- Copy the script below into R to extract data from your Google Scholar profile. Save the script as
# load packages if (!require("pacman")) install.packages("pacman"); library(pacman) # conditional installation of the packages below p_load(scholar,ggplot2,scales) # cit <- get_citation_history('3FHDoL0AAAAJ&hl') p = ggplot(cit,aes(x=year,y=cites))+ geom_bar(stat='identity')+ theme_bw()+ xlab('Year')+ ylab('Citations') + scale_y_continuous(labels = number_format(accuracy = 1), breaks = round(seq(min(cit$cites), max(cit$cites), by = 1),1)) + scale_x_continuous(breaks = round(seq(min(cit$year), max(cit$year), by = 1),1)) + annotate('text',label=format(Sys.time(), "%Y-%m-%d"),x=-Inf,y=Inf,vjust=1.5,hjust=-0.05,size=3,colour='gray') + theme_classic() + theme(#axis.text.y = element_text(size=14), #axis.text.x = element_text(size=14), #axis.title.y = element_text(size=14), #axis.title.x = element_text(size=14), #panel.background = element_blank(), #panel.grid.major = element_blank(), #panel.grid.minor = element_blank(), #axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=1)) + ggtitle("Google Scholar Citations (updated daily)") png("/Users/hectorbahamonde/Dropbox/scholar_citations.png",width=2200,height=1000,res=250) print(p) dev.off()
- Make sure you replace
3FHDoL0AAAAJ&hlwith your Google Scholar user number. You can find yours in your Google Scholar profile URL. In my case that is,
…that is, your user name is whatever is right after
- This script is going to send the plot
scholar_citations.pngto your DropBox folder (make sure your DropBox folder is “/Users/HERE/…”).
Go to DropBox, and get a shareable link of the plot
Now the crontab part. Open terminal and type the following in this exact same order:
env EDITOR=nano crontab -eHit
enterThis task suppresses alerts sent to you every time the task is executed.
0 9 * * * /usr/local/bin/Rscript -e 'source("/Users/hectorbahamonde/hbahamonde.github.io/gscholar.R")'Hit
enterThis task is the R script task itself. This is ONE line, so make sure you copy and paste this line into terminal as one line.
o. This saves the crontab task. To be sure, this is the “o” character, not a zero (0).
enter. This one just accepts the task name.
x. And this one closes down crontab. Mac might ask you if you want to let Terminal to modify your files. Accept that.
OK; that was the crontab part.
All this process ensures that your machine will automatically execute the R script
gscholar.Revery day at 9AM (make sure your computer is turned on by that time otherwise, crontab won’t be able to execute this task). If you need more specific times, see this link and replace the
0 9 * * *part with another time configuration.
- Make sure the path of the script
gscholar.Ris correct in your case. That is, in your case it should be something like this:
- In your website, and using the shareable link of your
scholar_citations.pngplot (as described in step 2), insert the following HTML code to embed your daily-generated Google Scholar citations plot into your website. The DropBox link should go after
src=. Notice that you have to replace whatever is after the
<img src="https://www.dropbox.com/s/hlroz3qjeyrwmta/scholar_citations.png?raw=1" alt="gscholar" style="width:800px;height:600;;border:0;">
I borrowed this from Ole Michelsen. I also got help from here. And from here. This one was important because my terminal window was very narrow, and I think it was indenting the crontab task described in 3.b in two lines, causing the task not to save. Thanks guys!