Run if you don’t have these:

install.packages(c("ggplot2", "scatterplot3d", "car"))

ANCOVA-type plot for one categorical and two continuous variables

bp <- read.csv("sbp.csv")
names(bp) <- tolower(names(bp))
bp$smk.f <- factor(bp$smk, labels = c("nonsmoker", "smoker"))

fit2 <- lm(sbp ~ age + smk.f, bp)

library(ggplot2)
plot <- ggplot(bp, aes(age, sbp, col = smk.f)) + geom_point() + theme_classic()

grid <- with(bp, expand.grid(
  age = seq(41, 65, length=length(age)), 
  smk.f = smk.f))

grid$sbp <- predict(fit2, newdata=grid, type="response")
plot + geom_line(data=grid)

3D scatterplot with coloring and vertical lines

library(scatterplot3d) 

attach(bp)
plot1 <- scatterplot3d(age, quet, sbp, color = factor(smk+1), pch=16, type="h")

# plot1$plane3d() also adds a regression plane

Spinning 3D Scatterplot

library(car)
scatter3d(sbp ~ age + quet + smk.f, data = bp)
# This function authomatically draws a regression surface - two actually, which
# is very handy

Plot opens in a new window, but this is how it looks like:

alt text