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

Add option suppress_default_hovertext for plot_method = "ggplot" #301

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions R/heatmaply.R
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ heatmaply.default <- function(x,
label_format_fun = function(...) format(..., digits = 4),
labRow = NULL, labCol = NULL,
custom_hovertext = NULL,
suppress_default_hovertext = F,
col = NULL,
dend_hoverinfo = TRUE,
side_color_colorbar_len = 0.3,
Expand Down Expand Up @@ -757,6 +758,7 @@ heatmaply.default <- function(x,
scale = scale,
na.rm = na.rm,
custom_hovertext = custom_hovertext,
suppress_default_hovertext = suppress_default_hovertext,
labRow = labRow,
labCol = labCol,
...
Expand Down Expand Up @@ -808,6 +810,7 @@ heatmaply.default <- function(x,
point_size_name = point_size_name,
label_format_fun = label_format_fun,
dend_hoverinfo = dend_hoverinfo,
suppress_default_hovertext = suppress_default_hovertext,
side_color_colorbar_len = side_color_colorbar_len,
plotly_source = plotly_source,
height = height,
Expand Down Expand Up @@ -887,6 +890,7 @@ heatmaply.heatmapr <- function(x,
point_size_name = "Point size",
label_format_fun = function(...) format(..., digits = 4),
custom_hovertext = x[["matrix"]][["custom_hovertext"]],
suppress_default_hovertext = F,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

False not f

dend_hoverinfo = TRUE,
side_color_colorbar_len = 0.3,
plotly_source = "A",
Expand Down Expand Up @@ -1017,6 +1021,7 @@ heatmaply.heatmapr <- function(x,
point_size_name = point_size_name,
label_format_fun = label_format_fun,
custom_hovertext = custom_hovertext,
suppress_default_hovertext = suppress_default_hovertext,
showticklabels = showticklabels
)
} else if (plot_method == "plotly") {
Expand Down
33 changes: 23 additions & 10 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ggplot_heatmap <- function(xx,
point_size_name = "Point size",
label_format_fun = function(...) format(..., digits = 4),
custom_hovertext = NULL,
suppress_default_hovertext = FALSE,
showticklabels = c(TRUE, TRUE),
...) {
theme_clear_grid_heatmap <- theme(
Expand Down Expand Up @@ -60,11 +61,14 @@ ggplot_heatmap <- function(xx,
col <- label_names[[2]]
val <- label_names[[3]]

mdf[["text"]] <- paste0(
row, ": ", mdf[[1]], "<br>",
col, ": ", mdf[[2]], "<br>",
val, ": ", label_format_fun(mdf[[3]])
)
if(!suppress_default_hovertext)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same brace style as the rest of the code

{
mdf[["text"]] <- paste0(
row, ": ", mdf[[1]], "<br>",
col, ": ", mdf[[2]], "<br>",
val, ": ", label_format_fun(mdf[[3]])
)
}

if (type == "heatmap") {
geom <- "geom_tile"
Expand All @@ -77,10 +81,13 @@ ggplot_heatmap <- function(xx,
geom <- "geom_point"
geom_args <- list()
if (!is.null(point_size_mat)) {
mdf[["text"]] <- paste(
mdf[["text"]], "<br>",
point_size_name, ": ", label_format_fun(mdf[[4]])
)
if(!suppress_default_hovertext)
{
mdf[["text"]] <- paste(
mdf[["text"]], "<br>",
point_size_name, ": ", label_format_fun(mdf[[4]])
)
}
aes_mapping <- aes(
color = .data[[val]],
text = .data$text,
Expand All @@ -95,7 +102,13 @@ ggplot_heatmap <- function(xx,
}
}
if (!is.null(custom_hovertext)) {
mdf[["text"]] <- paste0(mdf[["text"]], "<br>", custom_hovertext)
if(!suppress_default_hovertext)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invert this if/else

{
mdf[["text"]] <- paste0(mdf[["text"]], "<br>", custom_hovertext)
} else
{
mdf[["text"]] <- reshape2::melt(as.matrix(custom_hovertext))[[3]]
}
}
geom_args[["mapping"]] <- aes_mapping

Expand Down
4 changes: 4 additions & 0 deletions man/heatmaply.Rd

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