我认为这就是您要的...请注意,您必须使用 aes_string() 函数才能正确显示图表
plots = list()
cols_to_plot <- colnames(iris)
for(i in 1:4){
grf = ggplot(data = iris, aes_string(x = "1:nrow(iris)", y = cols_to_plot[i], color = "Species")) +
geom_point() +
ylab(colnames(iris)[i])
plots = c(plots, list(grf))
}
do.call(grid.arrange, plots)
产生以下内容:

facet_wrap
GGplot2有一些非常棒的功能(您需要正确排列数据以利用它(想想“长而瘦的数据”)。
以tidyr
一种易于被打包接受的方式塑造数据方面做得ggplot2
很好ggvis
。
这就是它所显示的......

require(ggplot2)
require(tidyr) # to reshape the data
require(dplyr) # to add the column of rownumbers. not really necessary at all
iris %>%
mutate(rowNum = 1:nrow(.)) %>% #add the column of row numbers
gather(Measure, Value, -(Species:rowNum)) %>% #from tidyr package - this is what makes it long. Read the help on `gather` and `spread`
ggplot(aes(x = rowNum, y = Value, group = Species, color = Species)) +
geom_point() +
facet_wrap(~Measure, nrow = 2) # the nice n' easy part. Automatically plops it in your four separate charts based on the "Measure" variable (which was created when I made the data "long" instead of "wide").