使用ggpairs函数时,需要指定包含facet的列名。例如,数据集iris中的Species列指定了花朵的种类,可以将其作为facet的列。
代码示例:
library(GGally)
# 使用iris数据集,将Species列作为facet的列
ggpairs(iris, columns=1:4, ggplot2::aes(color = Species), upper = list(continuous = "density"), lower = list(continuous = "points"))
在这个例子中,我们将1到4列(即sepal_length、sepal_width、petal_length和petal_width)作为ggpairs的columns参数,并在ggplot2::aes中指定Species列作为颜色的分组变量,以便在图形中创建facet。