tooltips in R graphics; nytR package

December 28, 2009

(This article was first published on simon jackman's blog » R, and kindly contributed to R-bloggers)

At Doug Rivers’ suggestion, I started investigating tooltips as a way to label points in R graphs. An example appears at the top of my blog, where I plot the ideal points (revealed preferences) of the (current) 111th U.S. House of Representatives against Obama vote share in their district in 2008 (SVG).

I’m using the RSVGTipsDevice package in R for this, which seems to be the only way to get tooltips into R graphics output. SVG is a reasonable enough vehicle when pushing output to the web, but PDF would be preferable.

As far as I can tell, (a) the “raw” PDF one needs to generate a tooltip isn’t difficult, and there are lots of examples out there to copy from (e.g., the various tooltip packages for pdftex), but (b) there is no way to push arbitrary PDF to a PDF device from R. Hacking/re-writing the pdf device in R might be one way to go, but I’m not going to do that. Post-processing the PDF with a program with decent PDF support might be another way to attack this (maybe python).

In other R-for-polisci news, Shane Conway told me about a R package he has but together for getting NYTimes data into R. The NYTimes has APIs letting you get into their in-house data, such as roll call data from the U.S. Congress. Shane’s package is essentially a R interface to to the NYTimes API for the Congressional data. Nice, although you’ll need a NYTimes API key for this. See also the R code snippet for NYTimes scraping from Stanford’s own Claudia Engel.

I use my own readKH function in pscl to hit Jeff Lewis’ site; Jeff scrapes the Congressional web sites in close to real time, but the NYTimes has some nice contextual data as well.

To leave a comment for the author, please follow the link and comment on their blog: simon jackman's blog » R. 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


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)