Tag Archives: ggplot2

Great circles on a recentered worldmap, in ggplot

Even though several examples of great circle visualizations exist by now, I had not seen the code of one made with ggplot2. Both solutions offered, here using plot and here using lattice, basically loop through the great circle lines ordered from low to high number of flights and overplot the lines with fewer counts, which are plotted in a light color with those with higher counts, which are plotted in a dark color.

In ggplot we can simply use the alpha parameter for transparency in combination with scale_colour_gradient to obtain a similar effect.

I am also addressing another issue here, namely the ability to flexibly recenter the world map to any longitude (not just 0 and 180) and to avoid the problem of split polygons.

Example data are all flights out of Beijing, China, downloaded from openflights.org.

Beijing - outgoing flights

Continue reading

Learning the Grammar of Graphics with R

During summer I usually spend a lot of hours locked up at an altitude of 30000+ feet, and this year I took ggplot2: Elegant Graphics for Data Analysis as reading material. ggplot2 is a data visualization package for the R statistical analysis platform. It is loosely based on “The Grammar of Graphics” from Leland Wilkinson, thus taking a different approach from traditional graphics packages by very explicitly mapping the data to aesthetic attributes (eg. colors) and geometric objects (eg. points).

Here is my first attempt to use the ggplot2 package. I was interested in the change of the mean population center of the US between 1790 and 2000, similar to the map that is put out by the Census Bureau, but specifically looking at the initially African, then African-American population.

I downloaded census data and county outlines from the National Historical Geographic Information System website, merged the data for each census year on the county level, and calculated the weighted mean for each census year. (Data are Tweets by @ceng_l