Smooth Scatter Plot

This example of how to use the smoothScatter() function from the Bioconductor geneplotter package was posted to Andrew Gelman’s blog by Gregor Gorjanc. The blog entry provides links to other resources for plotting large data sets.

##  Load BioConductor package "geneplotter", which requires
##  annotate, Biobase, and RColorBrewer.

library( package = "geneplotter" )

options( device = "X11" )

if ( interactive() )
{
    ##  Create a matrix where the first 5000 points are centered on [0,0]
    ##  and the second 5000 points are centered on [3,3].

    x1 <- matrix( rnorm( 1e4, mean = 0, sd = 1.0 ), ncol = 2 )
    x2 <- matrix( rnorm( 1e4, mean = 3, sd = 1.5 ), ncol = 2 )
    x <- rbind( x1, x2 )

    ##  The quartz device draws these figures poorly, so use the X11 device.
    ##  Use layout to set up a figure with four plots.

    X11()
    layout( matrix( 1:4, ncol = 2, byrow = TRUE ) )

    ##  Demonstrate four styles of smooth scatter plots.

    ##  Example 1:

    smoothScatter( x, nrpoints = 0 )

    ##  Example 2:

    smoothScatter( x )

    ##  Example 3:

    smoothScatter(
        x,
        nrpoints  = Inf,
        colramp   = colorRampPalette(
                       RColorBrewer::brewer.pal(
                           9,
                           "YlOrRd" ) ),
        bandwidth = 40 )

    ##  Example 4:

    colors <- densCols( x )
    plot( x, col = colors, pch = 20 )
}

The output is:

Four examples of smooth scatter plots

Four examples of smooth scatter plots