How to change the font style inside the HEATMAP boxes?

I'm having trouble changing the font style of correlation values inside the heatmap boxes to "Times New Roman"...Although I was able to change all the texts and numbers other than the correlation values inside the boxes in Times New Roman.. This is the code I'm using:

corrplot(cor(my.data))
cor = cor(my.data)
ggplot(cor)
my_plot<- ggcorrplot(cor, method = "square", type = "upper",
title = "Correlogram Cassia fistula",
legend.title = "Pearson Correlation",
lab = TRUE, lab_size = 3, lab_col = "black",
ggtheme = theme_minimal(),
outline.color = "white",
colors = c("#6D9EC1", "white", "#E46726")) +
theme(text = element_text(family = "Times New Roman"),
title = element_text(family = "Times New Roman"),
plot.title = element_text(family = "Times New Roman", face = "bold"),
axis.text = element_text(family = "Times New Roman"),
legend.text = element_text(family = "Times New Roman"))

try something like

update_geom_defaults(geom = "text", aes(family = "Times New Roman", fontface = "bold", size = 12/.pt))

Note: I divide the size by .pt to make the size compatible with the units that theme uses.

1 Like

Yes, it worked.. Thank you so much

To change the font style of the correlation values inside the heatmap boxes in ggcorrplot, you need to modify the lab_font argument, which controls the font appearance for labels inside the boxes. Update your ggcorrplot() call like this: lab_font = c("Times New Roman", 3, "plain"), where the elements represent font family, size, and face respectively. Here's the fix:

my_plot <- ggcorrplot(cor, method = "square", type = "upper",
title = "Correlogram Cassia fistula",
legend.title = "Pearson Correlation",
lab = TRUE, lab_size = 3, lab_col = "black",
lab_font = c("Times New Roman", 3, "plain"),
ggtheme = theme_minimal(),
outline.color = "white",
colors = c("#6D9EC1", "white", "#E46726")) +
theme(text = element_text(family = "Times New Roman"),
title = element_text(family = "Times New Roman"),
plot.title = element_text(family = "Times New Roman", face = "bold"),
axis.text = element_text(family = "Times New Roman"),
legend.text = element_text(family = "Times New Roman"))
This ensures even the labels inside heatmap tiles use "Times New Roman".

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.