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

前端 未结 1 1881
南笙
南笙 2021-01-25 05:45

I have a lattice plot of experimental data that has 4 datasets (i.e. 4 different subsets in \"Config.\" below), each dataset subdivided according to the config and then also gro

相关标签:
1条回答
  • 2021-01-25 06:36

    This is best accomplished using panel.number(), which gives you access, inside the call to a custom panel function, to the index of the panel being currently plotted.

    Here's a simple reproducible example:

    library(lattice)
    lattice.options(default.theme = standard.theme(color = FALSE))
    COLORS = c("blue", "gold", "red", "green", "black", "grey")
    
    xyplot(mpg ~ disp | carb, data = mtcars,
           panel = function(x,y,...) { 
               panel.xyplot(x, y, col=COLORS[panel.number()], pch=16, ...)
           })
    

    enter image description here

    A couple more involved examples are given here and here.

    0 讨论(0)
提交回复
热议问题