РЕДАКТИРОВАТЬ №.2
Теперь он использует намного превосходящий lapply
для графиков и построения в разумной структуре.
N = 100
matr <- matrix(rnorm(3*6*N), N)
matr_T <- array(as.vector(t(matr)), dim=c(6, 3, N))
apply(matr_T,1:2,mean)
apply(matr_T,1:2,sd)
library(ggplot2) # for histograms
library(cowplot) # for grid arrangement
# create list to access Dimensions in lapply
dims <- list(row = rep(1:nrow(matr_T),each = ncol(matr_T)),
col = rep(1:ncol(matr_T),times = nrow(matr_T)))
plots <- lapply(seq_along(dims$row),
function(i){
ggplot(data.frame(x = matr_T[dims$row[i],dims$col[i],]),aes(x = x)) +
geom_histogram(bins = 10, col = 'black', fill = 'white') +
theme_minimal() +
labs(title = paste('row:',dims$row[i],'\n','col:',dims$col[i]))
})
plot_grid(plotlist = plots, ncol = 3)
