Legend with ggplot2 with geom="path" and alpha option
I'm a R user from way back but struggling to get my head around ggplot2. In this example, I cannot get a legend when I use the geom="path" option also with the alpha setting. If I set geom="point" it appears fine.
tmp <- data.frame(cx=rnorm(21),cy=rnorm(21),labels=c(rep("a",7),rep("b",7),rep("c",7))) p1 <- qplot(data=tmp,cx,cy,geom="point",colour = labels, size=I(5), alpha=I(0.5))
Then the plot of points appears fine, including a legend with the correct alpha setting showing the dots. Adding in geom="path"
p2 <- qplot(data=tmp,cx,cy,geom="path",colour = labels, size=I(5), alpha=I(0.5))
Gets me a plot with the lines joined and correctly plotted with the alpha setting, and the legend also appears but is blank - eg. no alpha colors.
Is this possible to do?
It all works fine by dropping off the alpha parameter and I get solid colors in the plot and also the legend.
Update: Thanks for your comments so far but I guess this is just me or my setup as I still have this issue. An example of what I get in the link ...
And for completeness...
> sessionInfo() R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit) locale:  LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252  LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages:  grid stats graphics grDevices utils datasets methods base other attached packages:  scales_0.2.1 ggplot2_0.9.1 loaded via a namespace (and not attached):  colorspace_1.1-1 dichromat_1.2-4 digest_0.5.2 labeling_0.1 MASS_7.3-17 memoise_0.1  munsell_0.3 plyr_1.7.1 proto_0.3-9.2 RColorBrewer_1.0-5 reshape2_1.2.1 stringr_0.6  tools_2.15.0
I was finally able to reproduce what you are seeing, but only under very specific circumstances (and quite by accident that I happened to stumble across it). Given the circumstances, I'm pretty sure being on Windows (or rather, using the windows device driver) is necessary.
Using tmp, p1, p2 from the question:
dev.new() p1 p2
The dev.new() is important so that you are starting with a fresh window (because something becomes corrupted later). These commands give appropriate plots (don't do anything with the plot window). Now, if you "scroll" (History -> Previous or Next) or resize window at this point, nothing is drawn in the legend boxes. Prior to doing that, can save and get the right legend. After doing that, saving (File -> Save as...), legend boxes are blank. If you use the "scroll" option (I got it using the mouse wheel, repeatedly scrolling down, as I don't have recording on by default and therefore the Previous and Next options are grayed out), I (eventually) get the following on the console:
Error: VECTOR_ELT() can only be applied to a 'list', not a 'character'
which can be repeated some number of times before I eventually get:
Error: REAL() can only be applied to a 'numeric', not a 'character'
A workaround is to use ggsave. Since that creates a new device, you don't have to worry about the windows device getting into some broken state.
I think the behavior I'm seeing is a bug in the windows graphics device.