RStudio中的半透明 [英] Semi-transparency in RStudio

查看:753
本文介绍了RStudio中的半透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在回归线周围创建一个半透明置信区域的情节:

  library(car )
图书馆(ggplot2)
图书馆(效果)
$ b $ mod <-lm(薪水〜yrs.service +性别,数据=薪水)

yrseff< - as.data.frame(allEffects(mod)[[1]])

ggplot(yrseff,aes(x = yrs.service,y = fit))+
geom_ribbon(aes(ymin = lower,ymax = upper),alpha = .2)+
geom_line(color =darkgreen,size = 2)

我得到这个错误信息:


警告信息:
在grid.Call.graphics(L_polygon,x $ x,x $ y,index)中:
半透明在此设备上不受支持:每页仅报告一次



然而,如果我第一次打开一个pdf设备(如下面的代码),它会创建一个带有半透明功能区的pdf文件。



  pdf()
ggplot(yrseff,aes(x = yrs.service,y = fit) )+
geom_ribbon(aes(ymin = lower,ymax = upper),alpha = .2)+
geom_line(color =darkgreen,size = 2)
dev.off()

可能是什么问题?有没有办法获得半透明,而不必保存到PDF?



我在Ubuntu 12.04上使用RStudio,这是我的会话信息。

 > sessionInfo()
R版本3.0.3(2014-03-06)
平台:i686-pc-linux-gnu(32位)

语言环境:
[1] LC_CTYPE = en_CA.UTF-8 LC_NUMERIC = C LC_TIME = en_CA.UTF-8
[4] LC_COLLATE = en_CA.UTF-8 LC_MONETARY = en_CA.UTF-8 LC_MESSAGES = en_CA.UTF-8
[7] LC_PAPER = en_CA.UTF-8 LC_NAME = C LC_ADDRESS = C
[10] LC_TELEPHONE = C LC_MEASUREMENT = en_CA.UTF-8 LC_IDENTIFICATION = C

附加基础包:
[1] grid stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggplot2_0.9.3.1 car_2.0-19 effects_3.0-0 colorspace_1.2-4
[5] lattice_0.20-27

通过命名空间加载(并未附加):
[1] dichromat_2.0-0 digest_0.6.4 gtable_0.1.2 labeling_0.2
[5] MASS_7.3-29 munsell_0.4.2 nnet_7.3-7 plyr_1.8.1
[9] proto_0.3-10 RColorBrewer_1。 0-5 Rcpp_0.11.1 reshape2_1.2.2
[13] scales_0.2.3 stringr_0.6.2 tools_3.0.3


$ b $如果这是有用的信息:

  getOption(device)
[1] RStudioGD


解决方案

p>

您可以在配置中粘贴 getOption(bitmapType)的输出吗?如果它不是 cairo ,请尝试通过 options(bitmapType =cairo)来设置它,看看你是否得到相同的错误。


I'm trying to create a plot with a semi-transparent confidence region around the regression line:

library(car)
library(ggplot2)
library(effects)

mod <- lm(salary~yrs.service+sex, data=Salaries)

yrseff <- as.data.frame(allEffects(mod)[[1]])

ggplot(yrseff, aes(x=yrs.service, y=fit))+
geom_ribbon(aes(ymin=lower, ymax=upper), alpha=.2)+
geom_line(colour="darkgreen", size=2)

I get this error message:

Warning message: In grid.Call.graphics(L_polygon, x$x, x$y, index) : semi-transparency is not supported on this device: reported only once per page

However, if I first open a pdf device (as in code below) it creates a pdf file with the semi-transparent ribbon.

pdf()
ggplot(yrseff, aes(x=yrs.service, y=fit))+
geom_ribbon(aes(ymin=lower, ymax=upper), alpha=.2)+
geom_line(colour="darkgreen", size=2)
dev.off()

What might be the problem? Is there a way to obtain semi-transparency without having to save to a pdf?

I'm using RStudio on Ubuntu 12.04 and here is my session info.

> sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: i686-pc-linux-gnu (32-bit)

locale:
[1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8       
[4] LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
[7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.9.3.1  car_2.0-19       effects_3.0-0    colorspace_1.2-4
[5] lattice_0.20-27 

loaded via a namespace (and not attached):
[1] dichromat_2.0-0    digest_0.6.4       gtable_0.1.2       labeling_0.2      
[5] MASS_7.3-29        munsell_0.4.2      nnet_7.3-7         plyr_1.8.1        
[9] proto_0.3-10       RColorBrewer_1.0-5 Rcpp_0.11.1        reshape2_1.2.2    
[13] scales_0.2.3       stringr_0.6.2      tools_3.0.3 

And, in case this is useful information:

getOption("device")
[1] "RStudioGD"

解决方案

per request of the OP:

Can you paste the output of getOption("bitmapType") in your config? If it's not "cairo" try setting it to that via options(bitmapType="cairo") and see if you get the same error.

这篇关于RStudio中的半透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆