Skip to content

Commit

Permalink
Handling blocks with buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerssam committed Feb 26, 2024
1 parent 16fbb52 commit f68fafd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 8 additions & 5 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,22 @@ autoplot.design <- function(object, rotation = 0, size = 4, margin = FALSE, pale
block = sort(unique(object$block)),
xmin = 0, xmax = 0, ymin = 0, ymax = 0
)
if(!missing(buffer)) {
object <- create_buffers(object, type = buffer, blocks = TRUE)
if("buffer" %in% levels(object$treatments)) {
colour_palette <- c(colour_palette, "white")
}
}
for (i in 1:nrow(blkdf)) {
item <- blkdf$block[i]
tmp <- object[object$block == item, ]
tmp <- object[object$block == blkdf$block[i], ]
blkdf[i, "ymin"] <- (min(tmp$row) - 0.5)
blkdf[i, "ymax"] <- (max(tmp$row) + 0.5)
blkdf[i, "xmin"] <- (min(tmp$col) - 0.5)
blkdf[i, "xmax"] <- (max(tmp$col) + 0.5)
}
if(!missing(buffer)) {

}
plt <- ggplot2::ggplot(...) +
ggplot2::geom_tile(data = object, mapping = ggplot2::aes(x = col, y = row, fill = treatments), colour = "black", ...) +
ggplot2::geom_tile(data = object, mapping = ggplot2::aes(x = col, y = row, fill = treatments), colour = "black") +
ggplot2::geom_text(data = object, mapping = ggplot2::aes(x = col, y = row, label = treatments), colour = object$text_col, angle = rotation, size = size, ...) +
ggplot2::geom_rect(
data = blkdf,
Expand Down
13 changes: 12 additions & 1 deletion R/create_buffers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#'
#' @param design The data frame of the design.
#' @param type The type of buffer. One of edge, row, column, double row, double column, or block (coming soon).
#' @param blocks Does the design data frame contain blocks?
#'
#' @return The original data frame, updated to include buffers
#' @keywords internal
create_buffers <- function(design, type) {
create_buffers <- function(design, type, blocks = FALSE) {
nrow <- max(design$row)
ncol <- max(design$col)

Expand Down Expand Up @@ -65,12 +66,22 @@ create_buffers <- function(design, type) {
stop("Invalid buffer option: ", type, call. = FALSE)
}


buffers <- data.frame(matrix(NA, nrow = n_brow, ncol = ncol(design)))
buffers <- setNames(buffers, names(design))
buffers$row <- row
buffers$col <- col
buffers$treatments <- factor(treatments)

if(blocks) {
blocks_df <- aggregate(cbind(row, col) ~ block, data = design, FUN = max)
blocks_df$row[blocks_df$row==max(blocks_df$row)] <- max(blocks_df$row)+1
blocks_df$col[blocks_df$col==max(blocks_df$col)] <- max(blocks_df$col)+1
for(i in max(blocks_df$block):1) {
buffers[buffers$row <= blocks_df$row[i]&buffers$col <= blocks_df$col[i],"block"] <- blocks_df$block[i]
}
}

design <- rbind(design, buffers)

return(design)
Expand Down

0 comments on commit f68fafd

Please sign in to comment.