## ----corrgram-lattice-correlation-matrix, fig.width=6, fig.height=6---------------------
library("lattice")
library("corrgram")

# The easiest way to have an automatic color key is to set the theme
opar <- trellis.par.get()
trellis.par.set(
  regions=list(col=colorRampPalette(c("red","salmon","white","royalblue","navy")))
)

# Create a correlation matrix
library(MASS) # foor Cars93
cor.Cars93 <-   cor(Cars93[, !sapply(Cars93, is.factor)], use = "pair")
ord <- order.dendrogram(as.dendrogram(hclust(dist(cor.Cars93))))
cars93 <- cor.Cars93[ord,ord]
head(cars93)

# lattice corrgram using pie-shaped glyphs
levelplot(cars93, xlab = NULL, ylab = NULL,
          at = do.breaks(c(-1.01, 1.01), 101), panel = levelplot_panel.pie,
          scales = list(x = list(rot = 90)), colorkey = list(space = "top") )

# lattice corrgram using ellipse-shaped glyphs above the diagonal
# and value labels below the diagonal
levelplot(cars93, xlab = NULL, ylab = NULL,
          at = do.breaks(c(-1.01, 1.01), 101), panel = levelplot_panel.ellipse,
          label=TRUE,
          scales = list(x = list(rot = 90)), colorkey = list(space = "top") )


## ---------------------------------------------------------------------------------------
pengvars <- c("bill_len", "bill_dep", "flipper_len", "body_mass")
library(lattice)
splom(~penguins[ , pengvars], upper.panel=splom_panel.pie, pscales=0)
splom(~penguins[ , pengvars]|penguins$species, upper.panel=splom_panel.pie, pscales=0)
splom(~penguins[ , pengvars], upper.panel=splom_panel.shade, pscales=0)
splom(~penguins[ , pengvars]|penguins$species, upper.panel=splom_panel.shade, pscales=0)
splom(~penguins[ , pengvars], upper.panel=splom_panel.ellipse, pscales=0)
splom(~penguins[ , pengvars]|penguins$species, upper.panel=splom_panel.ellipse, pscales=0)

## ---------------------------------------------------------------------------------------
# Hexbin
library(lattice)
library(hexbin)
splom(~penguins[ , pengvars], upper.panel=hexbin::panel.hexbinplot, pscales=0)
splom(~penguins[ , pengvars]|penguins$species, upper.panel=hexbin::panel.hexbinplot, pscales=0)

