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 ...

http://i.stack.imgur.com/LiEwD.jpg

And for completeness...

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252       LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    
attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] scales_0.2.1  ggplot2_0.9.1
loaded via a namespace (and not attached):
[1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       labeling_0.1       MASS_7.3-17        memoise_0.1       
[7] munsell_0.3        plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5 reshape2_1.2.1     stringr_0.6       
[13] tools_2.15.0  

Answers


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.

ggsave("tmp.jpg", p2)

I think the behavior I'm seeing is a bug in the windows graphics device.


Need Your Help

MinGW gcc malloc issue with -fno-builtin

c gcc gdb mingw

I am having a strange problem with malloc and free in MinGW gcc

Elegant solution to parse date

java datetime java-8 java-time

I want to parse some text into a date. However, there is no guarantee that the text has the desired format. It may be 2012-12-12 or 2012 or even .