Skip to content

Commit

Permalink
Heatmap finished
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerssam committed May 31, 2024
1 parent 29e934e commit df3827a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ importFrom(ggplot2,scale_y_reverse)
importFrom(ggplot2,stat_qq)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,vars)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,rainbow)
importFrom(graphics,plot)
Expand Down
13 changes: 8 additions & 5 deletions R/heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#' @param smooth Logical (default: `TRUE`). If `raster` is `TRUE`, interpolation can be applied across the grid to obtain a smoothed grid. Ignored if `raster` is `FALSE`.
#' @param palette Colour palatte to use. By default it will use the `viridis` (colour-blind friendly) palette. Other palettes available can be seen with [grDevices::hcl.pals()].
#'
#' @importFrom ggplot2 ggplot aes geom_tile geom_raster scale_fill_gradientn scale_x_continuous scale_y_continuous facet_wrap
#' @importFrom ggplot2 ggplot aes geom_tile geom_raster scale_fill_gradientn scale_x_continuous scale_y_continuous facet_wrap vars theme_bw
#' @importFrom rlang ensym enquo quo_is_null
#'
#' @return A `ggplot2` object.
#' @export
Expand All @@ -24,16 +25,16 @@
#' dat$groups <- sample(rep(LETTERS[1:6], times = 5))
#'
#' heat_map(dat, value, x, y)
#' heat_map(dat, "value", "x", "y", "groups")
heat_map <- function(data, value, x_axis, y_axis, grouping = NULL, raster = TRUE, smooth = FALSE, palette = "default") {

# TODO:
# - Error and sanity checking
# - What if grouping is NULL?
# - NSE

value <- rlang::ensym(value)
x_axis <- rlang::ensym(x_axis)
y_axis <- rlang::ensym(y_axis)
grouping <- rlang::enquo(grouping)

# Set the default palette to viridis
if(palette=="default") {
Expand All @@ -55,9 +56,11 @@ heat_map <- function(data, value, x_axis, y_axis, grouping = NULL, raster = TRUE
ggplot2::scale_x_continuous(expand = c(0, 0)) +
ggplot2::scale_y_continuous(expand = c(0, 0))

if(!is.null(grouping)) {
if(!rlang::quo_is_null(grouping)) {
grouping <- rlang::ensym(grouping)
plt <- plt + ggplot2::facet_wrap(vars({{ gropuing }}))
plt <- plt + ggplot2::facet_wrap(ggplot2::vars({{ grouping }}))
}

plt <- plt+ggplot2::theme_bw()
return(plt)
}
1 change: 1 addition & 0 deletions man/heat_map.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df3827a

Please sign in to comment.