Put Google Scholar citations on your personal website with R, scholar, ggplot2 and cron

May 20, 2015
By

(This article was first published on Bart Rogiers, and kindly contributed to R-bloggers)

 

I have been looking for a solution to put my Google Scholar citations on my personal website for quite some time now. Some apps/gadgets seem to have existed to do so (e.g. citations-gadget), but none seem to be functioning today because of changes at Google Scholar, and embedding your entire profile page won’t work either. Basically, I had given up my search for a solution, until a few months ago, I discovered a blog post on the R scholar package by James Keirstead (development is taking place on github).
For installing the R scholar package (and its dependencies) in Linux, it is possible you need to install the following packages first (I was running Linux Lite 2.0 on my personal laptop and had to do so):
sudo apt-get install libcurl4-openssl-dev libxml2-dev
Then install the R package using the conventional
install.packages('scholar')
in R. After loading the package, you can get the citation history from a Google Scholar profile page (citations per year, as displayed in the bar plot on the right-hand side of the page) using a single function call on the Google Scholar profile ID. Getting the data, and making a plot with the ggplot2 package, which contains a timestamp, is done as follows:
  library(scholar)
  library(ggplot2)
  cit <- get_citation_history('u421gfwAAAAJ')
  png('scholar_citations_u421gfwAAAAJ.png',width=800,height=300,res=150)
  ggplot(cit,aes(x=year,y=cites))+
    geom_bar(stat='identity')+
    theme_bw()+
    xlab('Year of citation')+
    ylab('Google Scholar\n cites')+
    annotate('text',label=format(Sys.time(), "%Y-%m-%d %H:%M:%S %Z"),x=-Inf,y=Inf,vjust=1.5,hjust=-0.05,size=3,colour='gray')
  dev.off()

With my own humble contribution to science, the resulting image is something like this:

Now, for the automation of this image creation task, you can save the above code as an R script, and simply use cron in Linux. To set up your task with crontab, use
crontab -e
in the terminal and add a single line of text with the instructions to run your script. If you want to execute the script hourly, all you have to do is add a line like this:
0 * * * * cd /home/your/folder && Rscript your_script.R
and save the file. If you do this in a publicly accessible folder, or you can make the image itself publicly accessible (options to do so are Google Drive, Ubuntu One, Dropbox, etc.), you can easily embed it on your personal website with an HTML tag. I currently have it set up like this, so it updates every hour when my personal laptop is switched on. The up-to-date version of the plot above should be online here.

Not so hard after all! 🙂

To leave a comment for the author, please follow the link and comment on their blog: Bart Rogiers.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)