Problem of alpha() with plot.background panel

922 views
Skip to first unread message

Matthieu Stigler

unread,
Aug 17, 2011, 4:40:10 AM8/17/11
to ggplot2
Hi

I wanted to use a background color for the full plot. That background
color is simply a "alpha" of another colors. I see following problems:

-ggplot 0.8.9: plot.background seems well interpreted, but not
panel.background!
-ggplot 0.9: somehow reversed... the color for panel is fine, but plot
shows white whatever the color is?!

Note it is not dependant on alpha(), also if alpha is specified within
rgb(), the problem appears!

library(ggplot2)

alphaCol<-"blue" # ok!
alphaCol<-rgb(0.3,0.23,0.34, alpha=0.5) #prob
alphaCol<-alpha("blue", 0.2) #prob

theme_update(
plot.background = theme_rect(fill = alphaCol),
panel.background = theme_rect(fill = alphaCol)
)

qplot(displ, hwy, data = mpg)

Thanks!

Mat


Heike Hofmann

unread,
Aug 17, 2011, 4:46:03 AM8/17/11
to Matthieu Stigler, ggplot2
Mat,

when you use alpha blending for colors, the alpha value adds up, if you plot objects on top of each other.
That's the reason why you get the result you want with a fully saturated colour, but not when you use alpha < 1.

Try to use a transparent background for your plot panel , and you will be fine, i.e.:

library(ggplot2)

alphaCol<-rgb(0.3,0.23,0.34, alpha=0.5) #prob

theme_update(
plot.background = theme_rect(fill = alphaCol),

panel.background = theme_rect(fill = -rgb(0.3,0.23,0.34, alpha=0))
)

qplot(displ, hwy, data = mpg)


Heike

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Matthieu Stigler

unread,
Aug 17, 2011, 9:41:19 AM8/17/11
to Heike Hofmann, ggplot2
Dear Heike

Thanks a lot for your quick answer!! Indeed this soved it... but I am
quite surprised... I thought plot.bkdg and panel.bkgd were not on top of
each other, but were involving different regions? Are other graphical
parameters like this? I.e., if I show two lines whihc overlap, both with
different alpha, would be there a risk?

Finally, concerning the 0.9 version, I noticed plot.bkgd is shown in
white... bug or feature?

Thanks!

Mat

Le 17/08/2011 10:46, Heike Hofmann a �crit :

Reply all
Reply to author
Forward
0 new messages