---
title: "Plot ISO 25178 parameters for data mining"
author: "Ivan Calandra"
date: "`r Sys.Date()`"
output:
  html_document:
    toc: true
    toc_depth: 5
    toc_float: true
    theme: cerulean
    highlight: pygments
params:
  data: 
    value: "Data/CoordSys_FLT1-7_50x.Rbin"
---

<!-- Define the Rbin-file to use on line 14 --> 
<!-- This Rbin-file must be in a 'Data' folder within the directory of the present Rmd file --> 

<!-- Define numeric variables to plot on lines 77-78 --> 
<!-- Define X, symbol and color variables to plot on lines 92 and 111 --> 

---

Rbin-file used for this script: **`r paste0("~/", params$data)`**


```{r Knitr Options, include=FALSE}
	knitr::opts_chunk$set(comment=NA, message=FALSE, indent="", error=TRUE)
```

---


### 1. Goal of the script
```{r, echo=FALSE}
dir.plots <- "Plots"
dir.create(dir.plots, showWarnings=FALSE)
```

The script will plot all ISO 25178 variables to see which ones should be used for further analysis.  
It will also plot the X/Y shift for each microscope.  

Scatterplot of each variable will be plotted.  
All plots will be saved in a subfolder "`r dir.plots`" within the directory of the present Rmd file, i.e. "`r paste("~",dir.plots,sep='/')`".


---


### 2. Load packages
```{r}
library(R.utils)
library(ggplot2)
library(tools)
```


---


### 3. Load data into R object
```{r}
imp.info <- file.info(params$data)
imp.data <- loadObject(params$data)
```

The imported file is: "`r paste0("~/", params$data)`"  
Its modification, 'last status change' (= 'creation' on Windows) and last access times are, respectively: "`r imp.info$mtime`", "`r imp.info$ctime`" and "`r imp.info$atime`".


---


### 4. Define numeric variables
```{r}
num.var.topo <- 19:47
num.var.shift <- 54:55
names(imp.data)[num.var.topo]
names(imp.data)[num.var.shift]
```


---


### 5. Plot each of the selected numeric variable
#### 5.1. ISO parameters
```{r}
for (i in num.var.topo){
	file.out <- paste0(basename(file_path_sans_ext(row.names(imp.info))), "_plot_", names(imp.data)[i], ".pdf")
	p <- ggplot(data=imp.data, aes_string(x="Microscope", y=names(imp.data)[i], color="Microscope", shape="Microscope")) + geom_boxplot(outlier.shape=8) + geom_jitter(size=3, position=position_jitterdodge(jitter.width=0.7, dodge.width=0.7)) + theme_classic()
	print(p)
	ggsave(filename=file.out, path=dir.plots, device="pdf")
}
```

#### 5.2. X/Y shifts
```{r}
for (i in num.var.shift){
	file.out <- paste0(basename(file_path_sans_ext(row.names(imp.info))), "_plot_", names(imp.data)[i], ".pdf")
	p <- ggplot(data=imp.data[-c(1,11),], aes_string(x="Microscope", y=names(imp.data)[i], color="Microscope", shape="Microscope")) + geom_boxplot(outlier.shape=8) + geom_point(size=3, position=position_jitterdodge(jitter.width=0.7, dodge.width=0.7)) + ylim(0,130) + theme_classic()
	print(p)
	ggsave(filename=file.out, path=dir.plots, device="pdf")
}
```

#### 5.3. Summary
```{r, echo=FALSE}
files.out <- list.files(path=paste(getwd(),dir.plots,sep="/"), pattern=basename(file_path_sans_ext(row.names(imp.info))))
```

The following plot(s) was (were) created in and saved in "`r paste0('~/',dir.plots)`":  
```{r, echo=FALSE}
files.out
```


---

```{r}
sessionInfo()
```

---

END OF SCRIPT