【发布时间】:2019-02-10 22:29:19
【问题描述】:
我有一个名为 df
的数据框 clust gender conf chall
1 F 2 6
2 M 4 1
1 M 5 2
1 F 3 5
3 F 3 4
我想从 lattic 包中制作一个 xyplot,如下所示:
xyplot(chall ~ conf,
data = df,
group = gender,
auto.key = list(space = 'right'),
jitter.x = T, jitter.y = T)
问题在于默认颜色将“蓝色”分配给女性,将“粉红色”分配给男性。我只是想交换这些颜色。我知道这可能是一个基本问题,但我无法找到解决方案。
我查看的 SO 帖子是针对情节设置的更高级更改,对我没有用:
change background and text of strips associated to multiple panels in R / lattice
assigning colours to plots in lattice according to Set or factor, not groups
对此的任何帮助将不胜感激。
为方便起见,dput(df):
dput(df)
structure(list(clust = structure(c(1L, 2L, 1L, 1L, 3L),
.Label = c("1", "2", "3"), class = "factor"),
gender = c("F", "M", "M", "F", "F"),
conf = c(2L, 4L, 5L, 3L, 3L),
chall = c(6L, 1L, 2L, 5L, 4L)),
row.names = c(NA, 5L), class = "data.frame")
【问题讨论】: