R/plate_scheme.R

Defines functions .plate_scheme

#' @import ggplot2
#' @import ggthemes

.plate_scheme <- function(p,plate.layout) {

  p <- .fill_blank_cells(dat=p,layout=plate.layout)

  p[rxn.type=="NTC",alpha:=0.1]
  p[rxn.type=="Std",alpha:=0.5]
  p[rxn.type=="Unkn",alpha:=1]

  return(
    ggplot(data=p,mapping=aes(x=column,y=row,fill=target)) +



      theme_base() +

      theme(axis.ticks = element_blank(),legend.position="bottom") +



      scale_x_discrete(position="top") +

      scale_y_discrete(limits=rev(levels(p[,row]))) +

      scale_alpha_continuous(guide="none") +

      scale_fill_discrete(na.value="white",na.translate=FALSE) +



      labs(title=paste("Plate",unique(p[,plate])),
           x ="",y = "",fill="Target") +



      geom_tile(mapping=aes(alpha=alpha)) +

      geom_text(mapping=aes(label=fifelse(!is.na(rxn.type),
                                          paste0(rxn.type,"\n",
                                                 target),
                                          ""),
                            hjust=0,vjust=1,alpha=1),
                nudge_x=-0.45,nudge_y=0.45) +

      geom_text(mapping=aes(label=fifelse(rxn.type=="Unkn",
                                          paste0(sample,"\n","biol.repl. ",biol.repl),
                                          fifelse(rxn.type=="Std",
                                                  paste0(sample,"\n",dilution," ng/uL"),
                                                  "")),hjust=1,vjust=0,alpha=1),
                nudge_x=0.45,nudge_y=-0.45) +



      geom_hline(yintercept=seq(0.5,
                                length(levels(p[,row]))+0.5,
                                by=1)) +

      geom_vline(xintercept=seq(0.5,
                                length(levels(p[,column]))+0.5,
                                by=1))

  )
}
dimitriskokoretsis/qpcrR documentation built on May 29, 2022, 10:11 p.m.