Publications by is.R()

Conditional Colors and Shapes in plot() with ifelse()

09.10.2012

Here’s an example of how to color your plot shapes and pch using an ifelse() statement. Ifelse() is handy as it creates an easy way to branch a function. The syntax is: ifelse(logical.condition, option1, option2). Meaning, if the logical condition is met, use option 1, otherwise do option 2. Obviously this is a simple example of when to use...

1057 sym 2 img

Simple marimekko/mosaic plots

10.10.2012

I don’t really care for the name “marimekko” or “mosaic,” but I do like this type of plot as a means of illustrating proportions in nested categorical data, or as an alternative to the parallel time series plots discussed here (see this rather amateurish example). The Gist below is my attempt to make these somewhat complicated plots as...

1031 sym 4 img

From holey polygons to convex hulls

11.10.2012

I only rarely have the occasion to need the convex hull of a set of points, but I love chull(), so I’d like to share an example of how to use it. This Gist also offers a pretty straightforward application of the Split-Apply-Combine strategy (see lines 40-44), which is consistently useful, but complicated enough that it probably deserves its own...

774 sym 2 img

Using cairographics with ggsave()

12.10.2012

Whenever possible, I try to save R graphic output in a vector format, typically pdf(). I also like to use the handy ggsave() function to do so, as it streamlines the process, and makes it easy to be consistent across formats. However, at times it is necessary to use a bitmap graphical format, in which case I always prefer to use .pngs. The only d...

1093 sym 2 img

How to choose the right *apply function

13.10.2012

How to choose the right *apply function: This is an amazing stackoverflow answer to help you decide which of the many *apply functions (apply, lapply, sapply, vapply, mapply, rapply, tapply) is appropriate for the task at hand. I’m planning on doing some future post on some subset of these functions (and I use them when needed in many of the G...

803 sym

Banking to n degrees

15.10.2012

As often happens, I have learned of a technique just as it is being called into question. In this case, the technique is changing the aspect ratio of a line plot such that the typical slope of each segment is 45° (see), a rule of thumb which has been shown empirically to be sub-optimal. Despite my tardiness to the banking party, I’ve written ...

1199 sym 2 img

Gale-Shapley Deferred Acceptance in R

15.10.2012

In honor of today’s announcement of the Nobel Prize for Roth and Shapley, I found an illustration of the deferred acceptance algorithm from 1962 in R. Credit for the code goes to the blogger at Letters from London, and I’ve included a Gist below that illustrates the use of their deferred acceptance function. It looks like it’s supposed to...

945 sym 2 img

Flag space: a scatter plot of raster images

16.10.2012

(Click for a bigger version) I’m not sure when plotting raster images in an R scatter plot will end up being useful. It’s not something I expect to need to do in my day-to-day research, and I think in general probably adds more complexity than clarity, when used in “interesting” ways. That said, if the objects one wants to compare are the...

1614 sym 2 img

The distribution of ideology in the U.S. House (with plyr)

17.10.2012

This Gist has a couple of things going on, I’ll just list them: It downloads the entire history of U.S. House DW-NOMINATE scores from voteview.com It evaluates aggregate statistics, with members grouped by party and congress, with easy weighted functions from Hmisc. It does the aggregating and data.frame conversion all in one very easy step, us...

1008 sym 2 img

Faceting as a preferable alternative to 3-D

18.10.2012

Sometimes, people want to plot things in three dimensions. Others have spoken more eloquently than I could on the potential problems with plotting multiple two-dimensional relationships in a two-dimensional medium with an artificial three-dimensional visual effect. Fortunately, a third dimension can be easily represented without a faux-third dime...

1453 sym 2 img