xyplot如何交换默认颜色

时间:2019-02-10 22:29:19

标签: r colors lattice

我有一个名为 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帖子是用于情节设置的更高级更改,对我没有用:

  1. How can I change the color of the header in a xyplot?

  2. change background and text of strips associated to multiple panels in R / lattice

  3. assigning colours to plots in lattice according to Set or factor, not groups

  4. Change default colour lines xyplot with referencing

对此将提供任何帮助。

为方便起见,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")

1 个答案:

答案 0 :(得分:1)

通过par.settings参数传递符号的图形选项,该参数以一个列表作为参数,可用于设置颜色,点大小等。

xyplot(chall ~ conf, 
   data = df,
   group = gender, 
   auto.key = list(space = 'right'),
   jitter.x = T, jitter.y = T,
   par.settings = list(superpose.symbol = list(
    col = c("pink", "blue"), pch=16)))