`vignettes/ggformula-lattice.Rmd`

`ggformula-lattice.Rmd`

This document is intended to help users of the `mosaic`

package migrate their `lattice`

package graphics to `ggformula`

. The mosaic package provides a simplified and systematic introduction to the core functionality related to descriptive statistics, visualization, modeling, and simulation-based inference required in first and second courses in statistics.

Originally, the `mosaic`

package used `lattice`

graphics but now support is also available for the improved `ggformula`

system. Going forward, `ggformula`

will be the preferred graphics package for Project MOSAIC.

```
library(mosaic) # also loads ggformula
gf_histogram(~ age, data = HELPrct)
```

We can use stacked layers to add a density curve based on a maximum likelihood fit or a kernel density estimate (see also `gf_dist()`

)

### Density over histograms (lattice)

`mosaic`

makes it easy to add a fitted distribution to a histogram.

```
histogram(~ age, data = HELPrct,
fit = "normal", dcol = "red")
```

```
xyplot(cesd ~ age | sex, data = HELPrct,
type = c("p", "smooth"),
auto.key = TRUE)
```

```
xyplot(
cesd ~ age, data = HELPrct,
scales = list(y = list(log = TRUE)))
```

```
densityplot(
~ cesd, data = HELPrct, groups = sex,
rug = FALSE,
par.settings =
list(
superpose.line =
list(col = c("navy", "red")),
superpose.symbol =
list(col = c("navy", "red"))
))
```

Within RStudio, after loading the `mosaic`

package, try running the command `mplot(ds)`

where `ds`

is a dataframe. This will open up an interactive visualizer that will output the code to generate the figure (using `lattice`

, `ggplot2`

, or `ggformula`

) when you click on `Show Expression`

.

More information about `ggformula`

can be found at https://projectmosaic/github.io/ggformula.

More information regarding Project MOSAIC (Kaplan, Pruim, and Horton) can be found at http://www.mosaic-web.org. Further information regarding the `mosaic`

package can be found at https://projectmosaic.github.io/mosaic and https://journal.r-project.org/archive/2017/RJ-2017-02.

Examples of how to bring multidimensional graphics into day one of an introductory statistics course can be found at http://escholarship.org/uc/item/84v3774z.