¡Qué pasa, puto makina! 😎 Vamos al lío con ese pheatmap que te está quedando pro, pero la barra de color (legend) se te ve enana. Te explico todo y te doy opciones según lo que tú quieras: seguir con pheatmap, pasarte a ComplexHeatmap, o tunear a lo loco con ggplot2.
---
🧨 Problema: La leyenda (barra de color) es demasiado pequeña
🎯 Solución directa con pheatmap (truquillos)
La mala noticia: pheatmap no expone directamente el tamaño de la barra de color como parámetro.
La buena noticia: puedes forzarla manipulando el tamaño general del gráfico (output) y jugar con la escala de fuente fontsize.
Pero no puedes aumentar solo el tamaño de la barra de color directamente con pheatmap, a menos que edites el objeto gráfico (gtable/grob), o te pases a otras librerías.
---
🔥 OPCIÓN 1 – Usar grid para modificar la leyenda (sólo si vas a exportar o ajustar en un paso posterior)
library(pheatmap)
library(grid)
heat <- pheatmap(data,
color = colors,
breaks = breaks,
cluster_rows = TRUE,
cluster_cols = TRUE,
cellwidth = 5,
cellheight = 5,
fontsize = 20,
fontsize_row = 5,
fontsize_col = 5,
treeheight_row = 500,
treeheight_col = 500,
show_rownames = FALSE,
show_colnames = FALSE,
border_color = NA,
annotation_col = filtered_metadata,
silent = TRUE) # 👈 IMPORTANTE
# Extraer grob
g <- heat$gtable
# Agrandar la leyenda (esto es jodido y fino)
library(gridExtra)
grid.newpage()
grid.draw(g)
Pero si vas por ahí... mejor haces lo que viene abajo.
---
🚀 OPCIÓN 2 – Usa ComplexHeatmap (mucho más potente)
library(ComplexHeatmap)
col_fun <- colorRamp2(
breaks = seq(95, 100, length.out = 100),
colors = c("white", "blue", "yellow", "gold", "goldenrod1", "orange", "red")
)
Heatmap(data,
col = col_fun,
cluster_rows = TRUE,
cluster_columns = TRUE,
show_row_names = FALSE,
show_column_names = FALSE,
row_dend_height = unit(5, "cm"),
column_dend_height = unit(5, "cm"),
heatmap_legend_param = list(
title = "Intensidad",
title_gp = gpar(fontsize = 14),
labels_gp = gpar(fontsize = 12),
legend_height = unit(5, "cm") # 👈 TÚ DEFINES el tamaño
))
🔥 Esto te da control total sobre:
Tamaño y estilo de leyenda
Múltiples leyendas
Anotaciones pro
Exportación elegante
---
🧠 OPCIÓN 3 – Convertir a ggplot2 (con pheatmap::pheatmap(..., silent = TRUE) + gridExtra o ggplotify)
Muy fino pero más esfuerzo. Si solo necesitas la barra gorda, vete con ComplexHeatmap.
---
✅ Conclusión
Si te mola pheatmap y no quieres complicarte:
Exporta más grande (png(width = ..., height = ...))
Aumenta fontsize
Usa silent=TRUE y edita con grid.draw() (complicado)
Si quieres un control real: 👉 Cámbiate ya a ComplexHeatmap, cabrón. Vas a flipar con lo que puedes hacer.