【问题标题】:xyplot how to swap the default colourxyplot如何交换默认颜色
【发布时间】: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 帖子是针对情节设置的更高级更改,对我没有用:

  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")

【问题讨论】:

    标签: r colors lattice


    【解决方案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)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多