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

时间:2018-05-01 18:25:56

标签: r lattice

我想在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)
            })

1 个答案:

答案 0 :(得分:4)

十六进制值可以读作"#rrggbbaa",其中r =红色,g =绿色,b =蓝色,a = alpha。由于不透明度的十进制值范围为0到255,因此采用传统的rgb表示法; 30%不透明度的值为round((256/100)*30) = 77,其十六进制值为4d(有一个列表,其中包含一些示例here供参考,可以找到转换表dec - hex here)。

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

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

并删除

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

enter image description here