Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: How to overlay pie charts on 'dots' in a scatterplot in R

Using R I would like to replace the points in a 2d scatter plot by a pie chart displaying additional values.

The rational behind is that I have time series data for hundreds of elements (proteins) derived from a biological experiment monitored for 4 conditions. I would like to plot the elements (categorial data) on the y axis and occurrence of a event in time on the x axis. To visualize the relative occurrence between the 4 conditions I would like to visualize this in form of a pie chart or doughnut chart overplayed onto the respective point in the scatter plot. The overall data density is low so overlapping won't be an issue.

Is this possible in R? I was thinking of using a manual scale in ggplot2 but could not figure out how to define a pie chart as a scale.

Also of interest would be how to best cluster this data and sort it accordingly.

like image 231
philipp Avatar asked Feb 10 '12 18:02

philipp


People also ask

How do you overlay a pie chart?

Another reason that you may want to combine the pie charts is so that you can move and resize them as one. Click on the first chart and then hold the Ctrl key as you click on each of the other charts to select them all. Click Format > Group > Group. All pie charts are now combined as one figure.

Can pie charts overlap?

A common problem related to Pie Charts is the overlapping of the labels that represent data points with relatively small values, adjacent to each other. By default, the layout engine will try to arrange the data labels so they do not overlap.


2 Answers

Yes. pieGlyph() is one ready-to-go function from the Rgraphviz package.

Also, I would check out this Q/A for how to do things like this more generally:

How to fill a single 'pch' point on the plot with two-colours?

Especially check out ?my.symbols from the TeachingDemos package.

Lastly, in regards to ggplot2, you should check out this blog post about possible upcoming features:

http://blog.revolutionanalytics.com/2011/10/ggplot2-for-big-data.html

like image 167
John Colby Avatar answered Oct 01 '22 12:10

John Colby


See also Paul Murrell. Integrating grid graphics output with base graphics output. R News, 3(2):7-12, October 2003. http://www.r-project.org/doc/Rnews/Rnews_2003-2.pdf

The code on pp 10-11 sets up the main plot axes, labels and legend, and then opens a series of smaller windows centered at each individual point on the plot and plots a small graph in each window. I've tried pie charts, mosaics and barplots, but the method is not limited to these types.

like image 25
Alison Avatar answered Oct 01 '22 11:10

Alison