如何使用 ggplot 绘制由矩阵函数生成的意外事件 table?

how to plot with ggplot a contingency table generated with a matrix function?

列代表受访者的反应等级,行代表年龄组。 table 是用(矩阵?)生成的,目标是(图形?O 制作图形)不同年龄组的反应如何表现

tabla<-matrix(c(0,  0,  0,  1,  0,  0,  
                   1,   0,  0,  0,  9,  0,  
                   9,   1,  1,  5,  22, 0,  
                   18,  1,  3,  1,  27, 1,
                   25,  7,  4,  6,  22, 3,
                   20,  2,  0,  0,  18, 1,
                   6,   2,  0,  2,  22, 0,  
                   2,   0,  1,  1,  0,  4,  
                   12,  0,  0,  5,  6,  0),ncol=6,byrow=TRUE)
colnames(tabla)<-c("No","is a problem","lite preblem","a moderate proble","Big problem","No respond")
rownames(tabla)<-c("16-24.5","24.5-33","33-41.5","41.5-50","50-58.5","58.5-67","67-75.5","75.5-84","No responde")

我认为热图是一个不错的选择。这是使用 tidyverse 包的解决方案。

library(tidyverse)

tabla2 <- tabla %>%
  as.data.frame() %>%
  rownames_to_column() %>%
  gather(Column, Value, -rowname)

ggplot(tabla2, aes(x = rowname, y = Column, fill = Value)) +
  geom_tile() +
  scale_fill_gradientn(name = "", colors = terrain.colors(10)) +
  scale_x_discrete(name = "") +
  scale_y_discrete(name = "")