I was able to correct the error I was getting now I am having trouble with the x-axis labels. They're vertical, not horizontal. Also, the title isn't included in the image, regardless of the size I tried. Suggestions welcomed. Code below as requested.
#Install and load libraries
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install("ComplexHeatmap")
install.packages("openxlsx")
library(ComplexHeatmap)
library(openxlsx)
library(circlize)
library(grid)
#Read excel file
xxx_data <- read.xlsx("xxx_DEgenes.xlsx", sheet = "xxx_Rel_Data")
#Set gene column as row name
rownames(xxx_data) <- xxx_data$gene
xxx_data_matrix <- as.matrix(xxx_data[, c("logFC_15min", "logFC_30min", "logFC_45min", "logFC_75min")])
#Rename matrix columns
colnames(xxx_data_matrix) <- c("logFC 15min", "logFC 30min", "logFC 45min", "logFC 75min")
#QC data is correctly loaded and transformed
print(str(xxx_data_matrix))
#Replace NA values with 0
xxx_data_matrix[is.na(xxx_data_matrix)] <- 0
#Create color mapping
breaks = c(-8, 0, 8)
colors = c("darkblue", "white", "red")
#Generate and save heatmap with adjusted width and height
png("xxx_heatmap.png", width = 3000, height = 2000)
#Create custom features
heatmap_plot <- Heatmap(are_data_matrix,
col = colors,
name = "logFC ",
show_row_names = TRUE,
row_names_gp = gpar(fontsize = 12),
column_names_gp = gpar(fontsize = 12),
height = nrow(xxx_data_matrix) * 15.5,
width = ncol(xxx_data_matrix) * 0.9 #Adjust column width
)
# Print the heatmap
draw(heatmap_plot, annotation_legend_side = "bot")
# Add title back with adjusted positioning
grid.text("Differential Gene Expression in xxx Tomato", x = 0.5, y = 1.1, gp = gpar(fontface = "bold", fontsize = 14))
dev.off()