问题
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"
回答1:
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.
回答2:
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".
回答3:
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.
回答4:
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).
来源:https://stackoverflow.com/questions/22581567/semi-transparency-in-rstudio