Site icon R-bloggers

tooltips in R graphics; nytR package

[This article was first published on simon jackman's blog » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.