Search code examples
rgraphcomputer-sciencescatter-plot

Scatterplot Matrix showing bivariate data


I'm trying to do an example from the An Introduction to Applied Multivariate Analysis with R book. I can't figure out how to get this answer. You can get the data using library(HSAUR2) data("pottery")

Ex. 2.5 Construct a scatterplot matrix of the chemical composition of Romano-British pottery given in Chapter 1 (Table 1.3), identifying each unit by its kiln number and showing the estimated bivariate density on each panel.

I know this code is an example of the code I need but I'm having trouble changing everything to fit the pottery data:

library("KernSmooth")
CYGOB1d <- bkde2D(CYGOB1, bandwidth = sapply(CYGOB1, dpik))
plot(CYGOB1, xlab = "log surface temperature", ylab = "log light intensity")
contour(x = CYGOB1d$x1, y = CYGOB1d$x2, z = CYGOB1d$fhat, add = TRUE)

Solution

  • Your code does not produce a scatterplot matrix. It produces a single panel. Here is a way to adapt the code you included to the pottery data:

    potteryd <- bkde2D(pottery[, 1:2], sapply(pottery[, 1:2], dpik))
    plot(pottery[, 1:2], pch=as.numeric(pottery$kiln))
    contour(x = potteryd$x1, y = potteryd$x2, z = potteryd$fhat, add = TRUE)
    legend("topleft", levels(pottery$kiln), pch=as.numeric(levels(pottery$kiln)), title="Pottery Kiln")
    

    Density plot