library(knitr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(patchwork)

library(xtable)
options(xtable.comment = FALSE)

dat <- params[["data"]]

group_label <- unique(dat[["group_label"]])

dist_plot <- lapply(unique(dat[["Compound"]]), function(ith_cmp) {
  part_dat <- filter(dat, Compound == ith_cmp)

  hist <- ggplot(part_dat, aes(x = value, fill = group_label)) + 
    geom_histogram() +
    xlab("") +
    ggtitle("Histogram")

  qqplot <- ggplot(part_dat, aes(sample = value, color = group_label)) + 
    stat_qq() + 
    stat_qq_line() +
    ggtitle("Quantile-quantile chart")

  boxplot <- ggplot(part_dat, aes(x="", y = value, fill = group_label)) +
    geom_boxplot() +
    ggtitle("Boxplot")

  (hist + boxplot + qqplot)* facet_wrap(~ group_label, ncol = 1)* theme(legend.position = "bottom") + plot_annotation(paste0("Compound ", ith_cmp))
})


shapiro <- params[["shapiro"]]
tests <- params[["tests"]]
headers <- unique(dat[["Compound"]])
for (i in 1:length(headers)){
  cat("# Compound", headers[[i]], "\n")

  cat("## Normality", "\n")

  print(dist_plot[[i]])

  cat("#### Shapiro-Wilk Normality Test \n")

  print(kable(filter(shapiro, Compound == headers[[i]])))


  cat("## Between groups comparison \n")


  print(kable(filter(tests, Compound == headers[[i]])))

  cat("\\newpage")

}


michbur/easyR documentation built on Nov. 29, 2022, 6:46 a.m.