Reputation: 117
I want to increase the font size of the heatmap, but I found when the lengend name is long and legend group name is short, the legend will easily out of margin. Here is the example:
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
annotation_col = data.frame(
C = factor(rep(c("longCT1", "longCT2"), 5))
)
rownames(annotation_col) = paste("Test", 1:10, sep = "")
pheatmap::pheatmap(test,
annotation_col = annotation_col,
cluster_cols = F,
scale = "row",
fontsize = 20)
You can see the legend name C
is short and lengned group name longCTx
is longer, and when set a big font size, it will out of margin:
So in this case, how to fix it when I want to increase the font size of the heatmap?
Upvotes: 0
Views: 625
Reputation: 24272
A simple solution is to add some blanks at the end of the group names. See below:
# Add blanks to groups names
annotation_col = data.frame(
C = factor(rep(c("longCT1 ", "longCT2 "), 5))
)
rownames(annotation_col) = paste("Test", 1:10, sep = "")
pheatmap::pheatmap(test,
annotation_col = annotation_col,
cluster_cols = F,
scale = "row",
fontsize = 20)
Upvotes: 1