将Alpha值添加到点阵xyplot面板函数 [英] Add alpha value to lattice xyplot panel function
问题描述
我想在 xyplot
面板函数中分配两个alpha值:带有 alpha = 0.3
的 points 和带有 alpha = 1
的 lines .这是一个示例:
库(晶格)库(sp)数据(鼠标)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(空格='right',text = c("1","2","3"))),参数设置= list(superpose.symbol = list(pch = 20,cex = 1,col = c(#006837",#41ab5d",#fd8d3c"))),类型= c("p",平滑"),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 =α.由于不透明度的十进制值为0到255,因此采用传统的rgb表示法;30%不透明度的值应为 round((256/100)* 30)= 77
,而十六进制值为 4d
(有一些示例列表
I want to assign two alpha values in xyplot
panel function:
points with alpha= 0.3
and lines with alpha=1
.
Here is an example:
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)
})
An hex value can be read as "#rrggbbaa"
where r = red, g = green, b = blue and a = alpha. Since the decimal values for opacity range from 0 to 255, in a traditional rgb notation; the value for 30% opacity would be round((256/100)*30) = 77
, and hexadecimal value for this is 4d
(there is a list with some examples here for reference and a conversion table dec - hex can be found here).
Therefore, you just need to add 4d
at the end of your hex code for the points color as:
col = c("#0068374d", "#41ab5d4d","#fd8d3c4d")
and remove
panel = function(x, ...) {
panel.xyplot(x, ..., alpha = 0.3)
panel.lines(x, ..., alpha = 1)
}
这篇关于将Alpha值添加到点阵xyplot面板函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!