我想用for loop
生成ggplots
的列表。用于ggplot2中的循环生成列表
sig_snp<-c("rs644045_A","rs12997044_C","rs17739727_A")
p_re<-list()
for (i in sig_snp){
test %>% dplyr::select(i,type,micro1) %>%
ggplot(aes(factor(type),log(micor1))) +
geom_boxplot(aes(fill = factor(i)))+
xlab('')+ylab('log abundance')->p_re[[i]]
}
的埃罗如下所示:
Error: All select() inputs must resolve to integer column positions. The following do not: * i
我已经以这种方式测试了每个i
for循环:
test %>% dplyr::select(rs644045_A,type,micro1) %>%
ggplot(aes(factor(type),log(micor1))) +
geom_boxplot(aes(fill = factor(rs644045_A)))+
xlab('')+ylab('log abundance')
它的工作单,但为什么在循环无法正常工作?
'test'在哪里?请显示一个可重复的例子 – akrun
[关于如何给出一个可重复的例子的信息](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap
我认为这是一个语法问题:如何使for循环中的'i'被识别为没有引号的原始名称?当我在for循环中测试每个'i'时,它会单独工作。 – Ming