Semi-transparency in RStudio
Asked Answered
I

4

12

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"
Insurance answered 22/3, 2014 at 18:12 Comment(9)
FWIW, I don't get this error using 64-bit R V3.0.3 on Windows 7, using RStudio 0.98.501.Balsamic
I don't get an error on a mac, either.Illustrious
Same here. RStudioGD is also my graphics device and I'm on R 3.0.3 (OS X 10.9.2) but I am also running the preview release of RStudio ( 0.98.703).Scrawl
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.Scrawl
Read ?Devices. I'm pretty sure that there is a default interactive ggplot2 device that is system specific and I have seen descriptions of it 'somewhere', even if I cannot find the correct help page for it. pdf is simply not interactive.Liegnitz
I don't get the error either: Fedora 18 64-bit, R 3.0.2, RStudio 0.98.501Mountbatten
Setting bitmapType to "cairo" works. Thank you @hrbrmnstr!Insurance
@msoftrain, can you post this as an answer please?Cashmere
@Scrawl Your comment provided a solution to this question. Please post it as an answer.Pagano
S
15

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.

Scrawl answered 7/4, 2014 at 14:26 Comment(1)
Setting bitmapType to "cairo" solved the issue. Thank you.Insurance
F
12

I had exactly the same problem as the OP, but in my case setting options(bitmapType="cairo") did not solve the problem.

In my case the problem was caused by the fact that I compiled R manually from source without the --with-cairo configure option (or rather: my system was lacking the necessary libcairo2-dev package, the --with-cairo did not have any effect). Recompiling R with proper cairo support fixed the issue. It now even works although getOption("bitmapType") is still set to `"Xlib".

Furnary answered 14/10, 2014 at 11:38 Comment(1)
When building from source, I find it is helpful to run apt-get build-dep r-base-dev to make sure the system dependencies are installed. Some this is needed even when moving from R version x.y.z to R version x.y.(z + 1)Brightman
C
1

I have faced similar problems while running packages 'dismo' and 'ggplot2' in RStudio. As this problem started after I installed 'Ghostscript' into my Window_64, I removed all these folders from my computer in order to check if its works normally. RStudio worked normally without any error after removing 'Ghostscript'. However, by using options(bitmapType="cairo") as per above postings, I could resolve the error, but I had to rerun for every time for normal functioning of RStudio.

Chitwood answered 24/8, 2017 at 7:31 Comment(0)
C
0

I had the same problem under Ubuntu 16.04 when using RStudio with R v4.4.0. After updating R to v4.4.4 and running RStudio from terminal it was working fine.

Be aware that R version RStudio uses depends on the way you are starting the application (from desktop or terminal).

Conjoined answered 12/3, 2019 at 13:0 Comment(1)
R is now on version 4.2.1 this was not possible in 2019 as there isn't yet a R 4.4.0Denticulate

© 2022 - 2024 — McMap. All rights reserved.