【问题标题】:no additive transparency for geom_line()?geom_line() 没有附加透明度?
【发布时间】:2013-04-17 18:32:25
【问题描述】:

我注意到,当我使用 geom_line() 并渲染为 pdf 时,线条的 alpha 透明度不是相加的(与 geom_point() 相比)。有没有办法获得具有附加透明度的线条?

(想做类似于http://andrewgelman.com/2012/08/26/graphs-showing-regression-uncertainty-the-code/ 的事情)

【问题讨论】:

    标签: r ggplot2 transparency alpha


    【解决方案1】:

    以下代码显示 pdf 输出中的行透明度适用于我的设置:

    library(ggplot2)
    
    dat = data.frame(x1=0, x2=1, y1=rnorm(100), y2=rnorm(100))
    
    p = ggplot(dat, aes(x=x1, xend=x2, y=y1, yend=y2)) +
        geom_segment(alpha=0.2, size=2)
    
    ggsave("lines.pdf", plot=p, width=5, height=3)
    

    注意:此图像是 png 格式,但 pdf 在我的系统上看起来几乎相同。

    您的问题可能与操作系统或图形设备差异有关。

    sessionInfo()
    R version 2.15.3 (2013-03-01)
    Platform: i386-apple-darwin9.8.0/i386 (32-bit)
    
    locale:
    [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     
    
    other attached packages:
    [1] ggplot2_0.9.3.1
    

    【讨论】:

    • 2.15.3?!这是什么,2013?? :P
    猜你喜欢
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    • 2012-04-26
    • 2014-02-12
    • 1970-01-01
    • 2015-12-02
    相关资源
    最近更新 更多