Tuesday, May 11, 2010

Grammar of Graphics (ggplot2)

Grammar of Graphics (ggplot2)


This grammar, based on the Grammar of Graphics is composed of a set of independent components that can be composed in many different ways. This makes ggplot2 very powerful, because you are not limited to a set of pre-specified graphics, but you can create new graphics that are precisely tailored for your problem (Wilkinson, 2005).


Fig. 1. unemployment rate from 1940 to 2010

This plot, Fig 1 shows the unemployment rate over the last 70 years. The graph doesn’t tell us much about the unemployment rate, except for the peaks and lows. The following graph, Fig 2 shows the unemployment rate and the economic recession periods. Here, the graph is more informative as one can relate the two variables. We can safely assume that economic recession has negative impact on the employment rate.


Fig. 2. The rate of unemployment overlaid with period of recession



Fig. 3. number of unemployed people between 1967 and 2007

Fig 3 shows the fluctuation of the number of unemployed people between 1967 and 2007. The data is overlaid with the then presidents of the country. It is not very clear if there is any relationship between one party and the rate of unemployment, but the visualization is very powerful.


Fig. 4 miles per gallon by car type

Table. The first 10 cars in the mpg dataset, included in the ggplot2 package. cty and hwy record miles per gallon (mpg) for city and highway driving, respectively, and displ is the engine displacement in liters


Fig. 5. engine size vs miles per gallon of fuel consumed

A scatter plot of engine displacement in liters (displ) vs average highway miles per gallon (hwy). points are coloured according to number of cylinders. This plot summarizes the most important factor governing fuel economy: engine size.



Fig. 6. regression lines and standard deviation per engine size



Reference:

http://research.stlouisfed.org/fred2/series/AWHMAN

http://www.springerlink.com/content/u0v6xj/?p=6edcb7da7b034e88bfe162f2c976c240&pi=1


No comments:

Post a Comment