Publications by is.R()

Adding a background to your ggplot

19.10.2012

I really enjoy using the DW-NOMINATE data for examples, as I do here. Sometimes it’s useful to indicate regions in the background of a plot — perhaps two-dimensional regions of interest, perhaps one-dimensional periods in time. It’s not always obvious how to combine data from two data.frames to form one plot in ggplot2, so here is another ...

1216 sym 2 img

Distribution of colors by flag

22.10.2012

A story: We showed you how to use R to assess flag similarity and make a scatter plot of raster images. Dr. Wickham referred us to the set of 2400 flag icons made available by GoSquared, and then (probably jokingly) challenged us to replicate the cool plot of color-by-flag pie charts made by Shahee Ilyas. Of course, we accepted the challenge, bu...

1308 sym 2 img

Benchmarking matrix creation

23.10.2012

Sometimes it is useful to take a vector, or one column/row of a matrix, and build a new matrix of identical copies of that vector. There are lots of different ways to do this, but I just discovered a new, and very straightforward way to do this with matrix algebra, using the outer() function. However, I wanted to see whether this new approach was...

1589 sym 2 img

Plotting the debate "Winner"

24.10.2012

As a Political Scientist, it could not be more gauche to talk about the Presidential debate in terms of a winner and a loser, but the occasion provides the opportunity to show how to do (at least) three really useful things: Directly load price and volume data for InTrade contracts. All you need to know is the InTrade contractId, which can be fo...

1368 sym 2 img

Congressional ideology by state

25.10.2012

In a recent post, I illustrated how to add a background geom to your ggplot. While that code worked, and the plot looked fine, it was pointed out to me that I was missing an important aspect of plot layering with ggplot2. Namely, it is not, as I previously claimed, necessary to add extra NULL variables to the background data.frame. Fortunately, I...

1169 sym 2 img

Plotting correlation ellipses

26.10.2012

This is an oldie but a goodie. There are a lot of ways to plot multiple bivariate relationships, but this is one of my favorites, courtesy of the R Graph Gallery. https://gist.github.com/819111 Related To leave a comment for the author, please follow the link and comment on their blog: is.R(). R-bloggers.com offers daily e-mail updates about ...

583 sym 2 img

GGtutorial: Day 3 – Introduction to Colors

31.10.2012

So, where does ggplot get its colors? If you’ve ever asked ggplot to color on the basis of a factor, you might have beeen surprised by the default color choices.  The fact is, ggplot colors factors on the basis of finding evenly spaced colors around the HSL color circle, shown below: EDIT: ggplot2 actually uses HCL space, which is not the same...

1240 sym 6 img

GGtutorial: Day 4 – More Colors

01.11.2012

So far we’ve covered Melting and Casting data using the reshape() package and today we’re going to look at different ways of coloring and selecting palettes for plots. For these plots, we’re going to use the built in diamonds dataset that comes packaged in ggplot2.  Below I go through loading the data and selecting four different palett...

875 sym 4 img

GGtutorial: Day 5 – Gradient Colors and Brewer Palettes

02.11.2012

So, continuing with the short tutorials on how to do relatively simple (but sometimes very frustrating things) in ggplot, today’s post looks at how to use gradient colors and Brewer colors to color either continuous or discrete dependent variables.  If you have a continuous dependent variable, you’ll want to use a gradient option that gently...

1044 sym 12 img

Plotting letters as shapes in ggplot2

05.11.2012

This post is a little more esoteric than most, but I found myself needing to solve this problem, so I’m just passing the solution on to you. The plot above shows the distribution of DW-NOMINATE scores for the 18th Congress, with party indicated by both color and shape. You will notice that there are more parties in 1824 than there are today —...

1664 sym 6 img