【发布时间】:2014-06-01 19:19:35
【问题描述】:
我的数据集是一个data.frame NewAuto,它有名字:
[1] "mpg" "cylinders" "displacement" "horsepower" "weight"
[6] "acceleration" "year" "origin" "name" "MPG01"
我想用 ggplot 在一张图片上绘制七个图。它是更大代码的一部分。我的目标是制作与其他列相似的 mpg 图。每个图都应标有 y 轴。
SCATTERplots <- lapply(
2:8,
function( column ){
DataPlot <- ggplot(
data = NewAuto,
aes(
x = mpg,
y=NewAuto[,column]
)
)+geom_point()+facet_grid(.~MPG01)+ylab(names(NewAuto)[column])
return( DataPlot)
}
)
do.call( grid.arrange, SCATTERplots)
不幸的是,我得到了:
Error in `[.data.frame`(NewAuto, , column) : object 'column' not found
我该如何解决这个问题?
我是初学者,所以请考虑到这一点。
【问题讨论】: