【发布时间】:2023-02-26 10:27:44
【问题描述】:
我有代码来创建一个散点图矩阵,其中包含我希望根据数据集中的分类变量对其进行着色的密度曲线。我需要它来匹配特定的颜色,但我似乎无法让颜色从默认值更新。
下面是我试图用一个众所周知的数据集完成的概念示例(因为我的数据包含敏感信息并且无法发布)。
例如,如果我想使用 R 中的 crabs 数据集创建它,我会将分类变量分配给颜色和符号,例如:
species <- ifelse(crabs$sp == "B", "blue", "orange")
gender <- ifelse(crabs$sex == "M", "O", "+")
然后我想在我的矩阵和密度图中使用完全相同的符号和颜色:
ggpairs(crabs, columns=4:8, aes(color=species, shape=gender),
lower=list(continuous="smooth"), diag=list(continuous="densityDiag"))
但是,这会输出以下内容:
But the coral color should be blue, and the teal color should be true orange.
【问题讨论】: