Do this instead (add your labels to the data object, and then use geom_tile
and then geom_text
)
gg <- ggplot(data = cbind(melted_cormat,ids, ages),
aes(x=Var1, y=Var2, fill=value)) +
scale_x_discrete(labels = ids ) +
scale_y_discrete(labels = ids)
gg + geom_raster( aes(fill=value)) +
geom_text( aes(x=Var1, y=Var2, label = ages), color="red", size=3)
This brings the needed data into the naming environment where the gg-functions will be able to see those named columns. The geom_raster function builds an grid of cells to which attributes (“aesthetics”) such as color or text can be added. By default it mimics the base-graphics function image
upon which all of the heatmap-type functions derive by coloring with a color scale constructed using the range of the “fill”-aesthetic.
Output
5
solved How to put values to R Matrix cells?