将 alpha 值添加到 lattice xyplot 面板函数

Add alpha value to lattice xyplot panel function

我想在 xyplot 面板函数中分配两个 alpha 值: alpha= 0.3alpha=1。 这是一个例子:

library(lattice)
library(sp)
data(meuse)

xyplot(elev~ copper,data=meuse,groups=factor(soil),grid = TRUE,scales=list(tck=c(1,0), x=list(cex=1.1), y=list(cex=1.1)),
       auto.key = list(space = 'right',text=c("1", "2", "3")),
       par.settings = list(superpose.symbol = list(pch =20, cex = 1,
                                                   col = c("#006837", "#41ab5d","#fd8d3c"))),
      type = c("p", "smooth"),col.line =c("#006837", "#41ab5d","#fd8d3c"),lwd = 5,
      panel = function(x, ...) {
                panel.xyplot(x, ..., alpha = 0.3)
                panel.lines(x, ...,  alpha = 1)
            })

十六进制值可以读作 "#rrggbbaa",其中 r = 红色,g = 绿色,b = 蓝色,a = alpha。由于在传统的 rgb 表示法中,不透明度的十进制值范围为 0 到 255; 30% 不透明度的值将是 round((256/100)*30) = 77,十六进制值是 4d(有一个包含一些示例的列表 here for reference and a conversion table dec - hex can be found here)。

因此,您只需要在点颜色的十六进制代码末尾添加 4d 作为:

col = c("#0068374d", "#41ab5d4d","#fd8d3c4d")

并删除

panel = function(x, ...) {
            panel.xyplot(x, ..., alpha = 0.3)
            panel.lines(x, ...,  alpha = 1)
        }