2018-10-07
阅读量:
3162
R语言中assign函数在循环中出现的问题
代码如下:
for(i in 13:36){
assign(paste0("plot", i),ggplot(data = DOI, aes(x = origin_lat, y = DOI[,i], color = species))+
geom_smooth(method = "lm", formula = y~I(x*x)+x)+
geom_point()+guides(color = FALSE)+
labs(title = "", x = "", y = names(DOI)))
}
然后得到的结果是,总共14张图,变量名为plot13~36,每张图都是i=36的时候的数据做出的图,而纵坐标的label却是i=13~36。
但是如果我单独赋值i的话,运行前面代码中ggplot部分,就是正常的:
ggplot(data = DOI, aes(x = origin_lat, y = DOI[,i], color = species))+
geom_smooth(method = "lm", formula = y~I(x*x)+x)+
geom_point()+guides(color = FALSE)+
labs(title = "", x = "", y = names(DOI))
289.3747
9
2
关注作者
收藏
推荐帖子
0条评论
0条评论
0条评论