为什么grDevices颜色修饰符不适用于R中的`rug()`和`axis()`?

时间:2017-05-28 02:33:23

标签: r plot colors

我注意到有几个graphics函数(例如,rug())不适用于grDevices颜色修改函数(例如adjustcolor()rgb()等。 )。下面,我提供一些例子。

问题

既然adjustcolor()rgb()不起作用,我想知道rug()(见下文),我如何产生 透明效果 (又名alpha参数)在我的rug()来电中?

更新

即使我运行我们的同事, @AkselA rug()代码(请参阅下面的答案),我也无法复制他的结果。任何建议都表示赞赏。

x = rnorm(1e2)
hist( x )

 rug( x , col = adjustcolor("pink" , .5) ) # Doesn't work
 rug( x , col = rgb(1, 0, 0 , .5       ) ) # Doesn't work

 axis(1 , col = adjustcolor("pink" , .5) ) # Doesn't work
 axis(1 , col = rgb(1, 0, 0 , .5       ) ) # Doesn't work

plot( x , col = adjustcolor("pink" , .5) ) # works
plot( x , col = rgb(1, 0, 0 , .5       ) ) # works

1 个答案:

答案 0 :(得分:0)

它似乎对我来说非常合适,因为它应该是,因为这两个函数的输出只是一个简单的rgb十六进制字符串,它几乎被普遍接受为R函数中的颜色参数。

x = rnorm(1e2)

par(mfrow=c(1, 3), mar=c(2, 2, 2, 1))
hist(x)
rug(x, col = adjustcolor("red", 1), ticksize=0.05, lwd=0.6)

hist(x)
rug(x, col = adjustcolor("red", 0.3), ticksize=0.05, lwd=0.6)

hist(x); adjustcolor("red", 0.3)
rug(x, col = "#ff00004D", ticksize=0.05, lwd=0.6)

enter image description here

也许有些东西与设备有关。如果你尝试

会发生什么
png("rugRedTransparent.png", 550, 400)
hist(x)
rug(x, col = "#FF00004D", ticksize=0.05, lwd=1)
dev.off()