我想用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