可能重复:
ggplot - 函数输出方面
ggplot2
的facets
选项非常适合按因子显示多个图,但我在学习有效地将连续变量转换为其中的因子时遇到了困难。使用以下数据:
DF <- data.frame(WindDir=sample(0:180, 20, replace=T),
WindSpeed=sample(1:40, 20, replace=T),
Force=sample(1:40, 20, replace=T))
qplot(WindSpeed, Force, data=DF, facets=~cut(WindDir, seq(0,180,30)))
我得到错误:At least one layer must contain all variables used for facetting
我想Force~WindSpeed
通过离散的 30 度间隔来检查关系,但似乎facet
需要将因素附加到正在使用的数据框(显然我可以这样做DF$DiscreteWindDir <- cut(...)
,但这似乎没有必要)。有没有办法facets
在将连续变量转换为因子时使用?