Blog Archives

Consultants’ Chart in ggplot2

August 16, 2010
By
Consultants’ Chart in ggplot2

Excel Charts Blog posted a video tutorial of how to create a circumplex or rose or dougnut chart in Excel. Apparently this type of chart is very popular in the consulting industry, hence the “Consultants’ Chart”. It is very easy to make this chart in Excel 2010, but it involves countless number of clicks and

Read more »

ggplot2: Waterfall Charts

May 10, 2010
By
ggplot2: Waterfall Charts

Waterfall charts are often used for analytical purposes in the business setting to show the effect of sequentially introduced negative and/or positive values. Sometimes waterfall charts are also referred to as cascade charts. In the next few paragraphs I will show how to plot a waterfall chart using ggplot2. Data A very small fictional dataset

Read more »

ggplot2: Changing the Default Order of Legend Labels and Stacking of Data

March 23, 2010
By
ggplot2: Changing the Default Order of Legend Labels and Stacking of Data

“How to change the order of legend labels” is a question that gets asked relatively often on ggplot2 mailing list. A variation of this question is how to change the order of series in stacked bar/lineplots. While these two questions seem to be related, in fact they are separate as the legend is controlled by

Read more »

ggplot2: Plotting Dates, Hours and Minutes

February 24, 2010
By
ggplot2: Plotting Dates, Hours and Minutes

Plotting timeseries with dates on x-axis and times on y-axis can be a bit tricky in ggplot2. However, with a little trick this problem can be easily overcome. Let’s assume that I wanted to plot when the sun rises in London in 2010. sunriset function in maptools package calculates the sunrise times using algorithms provided

Read more »

ggplot2: Quick Heatmap Plotting

January 25, 2010
By
ggplot2: Quick Heatmap Plotting

A post on FlowingData blog demonstrated how to quickly make a heatmap below using R base graphics. This post shows how to achieve a very similar result using ggplot2. Data Import FlowingData used last season’s NBA basketball statistics provided by databasebasketball.com, and the csv-file with the data can be downloaded directly from its website. >

Read more »

ggplot2: Crayola Crayon Colours

January 21, 2010
By
ggplot2: Crayola Crayon Colours

Statistical Algorithms blog attempted to recreate a graph depicting the growing colour selection of Crayola crayons in ggplot2 (original graph below via FlowingData). He also asked the following questions: Is there an easier way to do this? How can I make the axes more like the original? What about the white lines between boxes and

Read more »

New Features in ggplot2 version 0.8.5

January 6, 2010
By
New Features in ggplot2 version 0.8.5

Just before Christmas ggplot2 version 0.8.5 was released, closely following the release of version 0.8.4 a week or so earlier. Whilst both versions included included numerous bugfixes (25 in 0.8.4 and 17 in 0.8.5), the latest version also incorporated some new features. As ggplot2 is all about graphical display, so I went through the list

Read more »

directlabels: Adding direct labels to ggplot2 and lattice plots

January 3, 2010
By
directlabels: Adding direct labels to ggplot2 and lattice plots

Sometimes it is preferable to label data series instead of using a legend. This post demonstrates one way of using labels instead of legend in a ggplot2 plot. > library(ggplot2) > p <- ggplot(dfm, aes(month, value, group = City, colour = City)) + geom_line(size = 1) + opts(legend.position = "none") > p + geom_text(data =

Read more »

Data Profiling in R

December 17, 2009
By
Data Profiling in R

In 2006 UserR conference Jim Porzak gave a presentation on data profiling with R. He showed how to draw summary panels of the data using a combination of grid and base graphics. Unfortunately the code has not (yet) been released as a package, so when I recently needed to quickly review several datasets at the

Read more »

ggplot2: Overplotting In a Faceted Scatterplot

December 3, 2009
By
ggplot2: Overplotting In a Faceted Scatterplot

Hadley Wickham recently shared a nice tip on how to get a faceted scatterplot plot with all points in the background of each plot. This technique makes a clever use of setting the faceting variable to NULL so that all points are plotted in light grey in all the facets. > library(ggplot2) > ggplot(mtcars, aes(cyl,

Read more »