library(ggplot2)
library(patchwork)
dat1 = read.csv('dat1.csv', row.names = 1)
p = lapply(dat1[,1:9], function(i){
ggplot(data = dat1, aes(x = group, y = i, color = group)) + geom_violin() +
ylab(names(dat1)[as.list(dat1) %in% list(i)]) +
xlab(NULL)
})
wrap_plots(p, nrow = 3, guides = 'collect')
系统内部会把X转为list,然后按列计算。
as.List()可以按列将数据转为List (因为一列是一个元素)
as.list(dat1) %in% list(i)是想找当前的在处理哪个i,以此取出列名