Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature added: layer_symbol() supports "freetext", and add color, size options #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export(annotation_point)
export(annotation_tile)
export(as_ComplexHeatmap)
export(heatmap)
export(layer_symbol)
export(layer_arrow_down)
export(layer_arrow_up)
export(layer_diamond)
Expand Down Expand Up @@ -40,6 +41,7 @@ importFrom(grDevices,colorRampPalette)
importFrom(grid,gpar)
importFrom(grid,grid.grabExpr)
importFrom(grid,grid.points)
importFrom(grid,grid.text)
importFrom(grid,unit)
importFrom(grid,unit.c)
importFrom(lifecycle,deprecate_warn)
Expand Down
29 changes: 24 additions & 5 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ add_annotation = function(my_input_heatmap,
#'
setGeneric("layer_symbol", function(.data,
...,
symbol = "point")
symbol = "point",
freetext = "",
color = "#161616",
size = 3)
standardGeneric("layer_symbol"))

#' layer_symbol
Expand All @@ -461,7 +464,10 @@ setGeneric("layer_symbol", function(.data,
#'
setMethod("layer_symbol", "InputHeatmap", function(.data,
...,
symbol = "point"){
symbol = "point",
freetext = "",
color = "#161616",
size = 3){

.data_drame = .data@data

Expand All @@ -474,7 +480,8 @@ setMethod("layer_symbol", "InputHeatmap", function(.data,
arrow_up = 24,
arrow_down = 25,
star = 8,
asterisk = 42
asterisk = 42,
freetext = 0
)

if(!symbol %in% names(symbol_dictionary) | length(symbol) != 1)
Expand Down Expand Up @@ -502,8 +509,20 @@ setMethod("layer_symbol", "InputHeatmap", function(.data,
row = !!.vertical %>% as.factor() %>% as.integer()
) |>
filter(...) |>
select(column, row) |>
mutate(shape = symbol_dictionary[[symbol]])
mutate(
shape = symbol_dictionary[[symbol]],
freetext = !!enquo(freetext),
color = !!enquo(color),
size = !!enquo(size)
) %>%
# {
# if(!is.null(freetext_col)){
# mutate(freetext = !!enquo(freetext_col)) %>%
# }else{
# mutate(freetext = "") %>%
# }
# } %>%
select(column, row, shape, freetext, color, size)
)

.data
Expand Down
26 changes: 17 additions & 9 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ InputHeatmap<-setClass(
left_annotation = tibble(col_name = character(), orientation = character(), col_orientation = character(), data = list(), fx = list(), annot = list(), annot_type= character(), idx = integer(), color = list(), further_arguments = list()),
group_top_annotation = list(),
group_left_annotation = list(),
layer_symbol = tibble(column = integer(), row = integer(), shape = integer())
layer_symbol = tibble(column = integer(), row = integer(), shape = integer(), freetext = character(), color = character(), size = integer())
)
)

Expand All @@ -49,8 +49,8 @@ InputHeatmap<-setClass(
#'
#' @importFrom methods show
#' @importFrom tibble rowid_to_column
#' @importFrom grid grid.points
#'
#' @importFrom grid grid.points grid.text
#'
#'
#' @name as_ComplexHeatmap
#'
Expand Down Expand Up @@ -130,15 +130,23 @@ setMethod("as_ComplexHeatmap", "InputHeatmap", function(tidyHeatmap){

# Filter just points to label
inner_join(tidyHeatmap@layer_symbol, by = c("row", "column")) |>
select(`index_column_wise`, `shape`)
select(`index_column_wise`, `shape`, `freetext`, `color`, `size`)

if(nrow(ind)>0)
ind_symbol = ind %>% filter(shape != 0)
ind_freetext = ind %>% filter(shape == 0)
if(nrow(ind_symbol)>0)
grid.points(
x[ind$index_column_wise], y[ind$index_column_wise],
pch = ind$shape ,
size = unit(3, "mm"),
gp = gpar(col = NULL, fill="#161616")
x[ind_symbol$index_column_wise], y[ind_symbol$index_column_wise],
pch = ind_symbol$shape ,
size = unit(ind_symbol$size, "mm"),
gp = gpar(col = NULL, fill=ind_symbol$color)
)

if(nrow(ind_freetext) > 0){
grid.text(
ind_freetext$freetext, x[ind_freetext$index_column_wise], y[ind_freetext$index_column_wise],
gp = gpar(fontsize = ind_freetext$size, col = ind_freetext$color))
}
}

return(do.call(Heatmap, tidyHeatmap@input))
Expand Down