Plot a matrix in R – for loop not working

I have a 6*5 matrix, I want to plot it, by giving some coordinates as a different colour. I tried by using a list of plots, but plots all coordinate as last number

plottlist <- list()
for(i in 1:nrow(mat3)){
  for (j in 1:ncol(mat3)){
    plott<-ggplot() + theme_void()+geom_text(aes(1,1,label = mat3[i,j]))
    plot2 <- list(plott)
    plottlist[paste0(i,j)]<- plot2
  }

}
grid.arrange(grobs=plottlist)

output ouput



Read more here: https://stackoverflow.com/questions/67010630/plot-a-matrix-in-r-for-loop-not-working

Content Attribution

This content was originally published by Knows_nothing at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: