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"
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). – ScrawlgetOption("bitmapType")
in your config? If it's not "cairo
" try setting it to that viaoptions(bitmapType="cairo")
and see if you get the same error. – Scrawlpdf
is simply not interactive. – LiegnitzbitmapType
to"cairo"
works. Thank you @hrbrmnstr! – Insurance