R has great graphics and plotting capabilities and can produce a wide range of plots very easily. The following is an R plot gallery with a selection of different R plot types and graphs that were all generated with R. In each case you can click on the graph to see the commented code that produced the plot in R. Note that the R code produces pdf files, which I have converted in gimp to png format for displaying on the web.


Plotting the kernel-smoothed distribution of galaxies in a cluster

This shows the spatial distribution of galaxies in the cluster Abell 85, using data from the NASA Extragalactic Database (NED). Overlaid are contours of kernel-smoothed number density, plotted using alpha blending (semi-transparency). Also included is an inset plot of the 1 dimensional kernel-smoothed redshift distribution, with the same colours as used in the main plot, which also serves as a key for the colour-code; the dashed curve is a Gaussian distribution with the same mean and standard deviation as the galaxy redshifts. Click the image to see the R source code. You can also view a larger version of the plot.

To follow a step-by-step tutorial showing how to create a similar plot in R, click here.

Abell 85 galaxy cluster

There is now a Birmingham (UK) R user group: click here for more information


Plotting time series using lattice graphics

An R chart of daily weather measurements taken at the University of Birmingham Wast Hill Observatory, using the excellent R lattice graphics package. The measurements are averaged over the 5 hours around midday except for rainfall, which is averaged over a week. Click the image to see the R source code. You can also view a larger version of the plot.

average daily weather

There is now a Birmingham (UK) R user group: click here for more information


Plotting lines profiles with error envelopes using ggplot2

Using ggplot2 to show mean temperature profiles and their error envelopes for cool-core and non-cool core clusters, from Sanderson et al. (2006). This plot was made with the outstanding ggplot2 package, which produces high-quality results in just a few short lines of R code. Note the use of semi-transparency to allow overlapping features to be viewed. Click the image to see the R source code.

CC vs. nCC T(r)

There is now a Birmingham (UK) R user group: click here for more information


A simple dotplot using lattice graphics

A plot of the distribution of redshifts for a sample of galaxy clusters observed with NASA's Chandra X-ray observatory. Points are colour-coded by cool core status and conditioned on detector type used (i.e. split into separate panels). Click the image to see the R source code. You can also view a larger version of the plot.

cluster redshift dotplot

There is now a Birmingham (UK) R user group: click here for more information


A simple boxplot using ggplot2

A boxplot of the distribution of midday outside temperatures from the above dataset as a function of month throughout 3 years of data. Click the image to see the R source code.

monthly temperature boxplot

There is now a Birmingham (UK) R user group: click here for more information


Plotting factors vs. factors

The following is summary of the numbers of proposals awarded by the XMM-Newton time allocation comittee for AO7 (Announcement of Opportunity), representing the priority ranking (A-C) vs. science category, with the widths of the columns proportional to the number of proposals accepted in that category. Click the image to see the R source code. XMM AO7 summary

There is now a Birmingham (UK) R user group: click here for more information


Plotting a function

A plot of some blackbody curves for 3 different temperatures. Click the image to see the R source code.

CC vs. nCC T(r)

There is now a Birmingham (UK) R user group: click here for more information


Plotting a galaxy spectrum

This is an optical spectrum of the classic Seyfert 2 galaxy NGC 1068 (M77), using two datasets available from the NASA Extragalactic Database (NED). Click the image to see the R source code.

M77 spectrum

There is now a Birmingham (UK) R user group: click here for more information


A simple scatter plot with errorbars

A plot of redshift vs. mean X-ray temperature, for a sample of galaxy clusters from Sanderson et al. (2006), colour-coded according to the presence or absence of a cool core. Click the image to see the R source code.

Cluster z vs kT

For further information, you can find out more about how to access, manipulate, summarise, plot and analyse data using R.


There is now a Birmingham (UK) R user group: click here for more information

Quick links


Jump to








Birmingham (UK) R user group

click here for more information

Copyright © 2010-2013 Alastair Sanderson