---
title: Testing the VI.ggplot() within the BrailleR package"
author: "A. Jonathan R. Godfrey"
bibliography: BrailleRPublications.bib
vignette: >
  %\VignetteIndexEntry{qplot}
  %\VignetteEngine{knitr::rmarkdown}
output: knitr:::html_vignette
---


This vignette  contained many more plots in its initial development. The set has been cut back considerably to offer meaningful testing only, and because much of the material was moved over to a book called [BrailleR in Action](https://R-Resources.massey.ac.nz/BrailleRInAction/). Doing so also had an advantage of speeding up the package creation, testing, and installation.
N.B.  the commands here are either exact copies of the commands presented in Wickham (2009) or some minor alterations to them.    Notably, some code given in the book no longer works. This is given a `#!`    


The `ggplot2` package has  a `summary` method that often but not always offers something to show that things have changed from one plot to another. Summary 
commands are included below but commented out.

```{r GetLibraries}     
library(BrailleR)   
library(ggplot2)   
library(magrittr)
dsmall = diamonds[1:100,]   
```  

```{r g1}     
g1 = qplot(carat, price, data = diamonds)   
# summary(g1)   
g1  
# VI(g1)   ### automatic since BrailleR v0.32.0
```  

```{r g2}          
g2 = qplot(carat, price, data = dsmall, colour = color)    
# summary(g2)   
g2
# g2 %>% VI()    ### automatic since BrailleR v0.32.0
```  



```{r g3}     
g3 = qplot(carat, price, data = dsmall, shape = cut)    
# summary(g3)   
g3
#VI(g3)     ### automatic since BrailleR v0.32.0
```  

```{r g4}     
# to get semi-transparent points   
g4 = qplot(carat, price, data = diamonds, alpha = I(1/100))    
# summary(g4)   
g4
# VI(g4)     ### automatic since BrailleR v0.32.0
```  

```{r g5}     
# to add a smoother (default is loess for n<1000)   
g5 = qplot(carat, price, data = dsmall, geom = c("point", "smooth"))    
# summary(g5)   
g5
# VI(g5)     ### automatic since BrailleR v0.32.0
#! g5a = qplot(carat, price, data = dsmall, geom = c("point", "smooth"), span = 1)    
library(splines)    
#! g5b = qplot(carat, price, data = dsmall, geom = c("point", "smooth"), method = "lm")    
#! g5c = qplot(carat, price, data = dsmall, geom = c("point", "smooth"), method = "lm", formula = y ~ ns(x,5))    
```  

```{r g6, include=FALSE}     
# continuous v categorical   
g6 = qplot(color, price / carat, data = diamonds, geom = "jitter", alpha = I(1 / 50))    
# summary(g6)   
g6
# VI(g6)     ### automatic since BrailleR v0.32.0
g6a = qplot(color, price / carat, data = diamonds, geom = "boxplot")    
# summary(g6a)   
g6a
# VI(g6a)     ### automatic since BrailleR v0.32.0
```  

```{r g7}     
# univariate plots   
g7a = qplot(carat, data = diamonds, geom = "histogram")    
# summary(g7a)   
g7a
# VI(g7a)     ### automatic since BrailleR v0.32.0
g7b = qplot(carat, data = diamonds, geom = "histogram", binwidth = 1, xlim = c(0,3))    
g7b
# VI(g7b)     ### automatic since BrailleR v0.32.0
g7c = qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.1, xlim = c(0,3))
g7c
# VI(g7c)    ### automatic since BrailleR v0.32.0
g7d = qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.01, xlim = c(0,3))    
# summary(g7d)   
g7d
#VI(g7d)     ### automatic since BrailleR v0.32.0
```  

```{r g8, include=FALSE}
g8 = qplot(carat, data = diamonds, geom = "density")    
# summary(g8)   
g8
# VI(g8)    ### automatic since BrailleR v0.32.0
```  

```{r g9, include=FALSE}     
# data is separated by implication using the following...   
g9 = qplot(carat, data = diamonds, geom = "density", colour = color)    
# summary(g9)   
g9
# VI(g9)     ### automatic since BrailleR v0.32.0
g10 = qplot(carat, data = diamonds, geom = "histogram", fill = color)    
# summary(g10)   
g10
# VI(g10)     ### automatic since BrailleR v0.32.0
```  

```{r g11}     
# bar charts for categorical variable   
g11a = qplot(color, data = diamonds)    
# summary(g11a)   
g11a
# VI(g11a)     ### automatic since BrailleR v0.32.0
g11b = qplot(color, data = diamonds, geom = "bar")    
# summary(g11b)   
g11b
# VI(g11b)    ### automatic since BrailleR v0.32.0
g12a = qplot(color, data = diamonds, geom = "bar", weight = carat)   
# summary(g12a)   
g12a
# VI(g12a)     ### automatic since BrailleR v0.32.0
g12b = qplot(color, data = diamonds, geom = "bar", weight = carat) + scale_y_continuous("carat")    
# summary(g12b)   
g12b
# VI(g12b)     ### automatic since BrailleR v0.32.0
```  

```{r g13}     
# time series plots   
g13a = qplot(date, unemploy / pop, data = economics, geom = "line")    
# summary(g13a)   
g13a
# VI(g13a)     ### automatic since BrailleR v0.32.0
g13b = qplot(date, uempmed, data = economics, geom = "line")    
# summary(g13b)   
g13b
# VI(g13b)     ### automatic since BrailleR v0.32.0
```  

```{r g14, include=FALSE}     
# path plots   
year <- function(x) as.POSIXlt(x)$year + 1900    
g14a = qplot(unemploy / pop, uempmed, data = economics, geom = c("point", "path"))    
# summary(g14a)   
g14a
# VI(g14a)     ### automatic since BrailleR v0.32.0
#g14b = qplot(unemploy / pop, uempmed, data = economics, geom = "path", colour = year(date)) + scale_area()    
#summary(g14b)   
#VI(g14b)   
```  

```{r g15, include=FALSE}     
# facets is the ggplot term for trellis' panels   
g15a = qplot(carat, data = diamonds, facets = color ~ ., geom = "histogram", binwidth = 0.1, xlim = c(0, 3))    
# summary(g15a)   
g15a
#VI(g15a)    ### automatic since BrailleR v0.32.0
g15b = qplot(carat, ..density.., data = diamonds, facets = color ~ ., geom = "histogram", binwidth = 0.1, xlim = c(0, 3))   
# summary(g15b)   
g15b
#VI(g15b)    ### automatic since BrailleR v0.32.0
```  

```{r g16}     
# rescaling of the axes   
g16 = qplot(carat, price, data = dsmall, log = "xy")   
# summary(g16)   
g16
#VI(g16)    ### automatic since BrailleR v0.32.0
```  

```{r g17, include=FALSE}     
# Facets syntax without a "." before the "~" causes grief
g17 = qplot(displ, hwy, data=mpg, facets =~ year) + geom_smooth()    
# summary(g17)   
g17
# VI(g17)    ### automatic since BrailleR v0.32.0
```  
