Thanks for your help!
You are right! Pheatmap can deal with annotation in this nice way!
Last night I tried with:
pheatmap(a,
show_rownames = F,
border_color = NA,
scale = "row",
clustering_distance_rows = "euclidean",
clustering_distance_cols = "euclidean",
clustering_method = "single",
labels_col = c("\nA", "", "", "", "", "", "", "","", "\nB", "", "", "", "", ""),
angle_col = 0)
But your solution is a way better

Try playing with
cell heightandwidthand change the x and y coordinates of the text. Or you can read more about grid.graphics used by pheatmap.