scale_colour_manual issues

606 views
Skip to first unread message

Nick S

unread,
Jun 2, 2010, 8:36:37 PM6/2/10
to ggplot2
I am noticing an issue with scale_colour_brewer and
scale_colour_manual and would like to solicit input on whether this is
a bug or I am not doing something correctly.

I am producing a plot with the following code:

p =
ggplot(plates3,aes(ce_coupling_efficiency,proportion,colour=category))
p + geom_step() +
scale_colour_manual(values=alpha(c("gold1","dodgerblue2"),0.6))

example image (http://dl.dropbox.com/u/3734701/
scale_colour_manual.jpg)

This results in a plot with empty legend boxes. The boxes have no
lines indicating the factor level.

If I produce the same plot...but specify the colours of the lines with
scale_colour_brewer...the plot legend is displayed as I would
expect...colored lines indicating the factors.

p =
ggplot(plates3,aes(ce_coupling_efficiency,proportion,colour=category))
p + geom_step() + scale_colour_brewer(palette="Set1")

example image (http://dl.dropbox.com/u/3734701/
scale_colour_brewer.jpg)

I'd like to understand why this doesn't work as I would like the
flexibility to specify colors for these types of plots. Thanks in
advance for any ideas.

Hadley Wickham

unread,
Jun 2, 2010, 8:58:27 PM6/2/10
to Nick S, ggplot2
Hi Nick,

it's hard to know without your data...

Hadley

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

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Nick S

unread,
Jun 2, 2010, 11:34:31 PM6/2/10
to ggplot2
Good point.

The data can be found here (http://dl.dropbox.com/u/3734701/
plates3.csv)

The exact code I use to produce the plots is below.

scale_colour_manual seems to place empty facet label boxes in the
legend...while scale_colour_brewer (commented out below) adds the
factor indicators that I would expect.


p =
ggplot(plates3,aes(ce_coupling_efficiency,proportion,colour=category))
p + geom_step() + geom_vline(xintercept=0.967,linetype=2,colour="red")
+
scale_colour_manual(values=alpha(c("gold1","dodgerblue2"),0.6)) +
#scale_colour_brewer(palette="Set1") +
xlim(0.95,1.0) +
labs(x="Coupling Efficiency", y="Proportion", colour = "Condition") +
opts(title=paste("20mer Oligo Quality - Before/After BBXL")) +
opts(plot.title=theme_text(size=11)) +
opts(axis.text.x=theme_text(size=9)) +
opts(axis.title.y=theme_text(angle=90,size=9)) +
opts(axis.title.x=theme_text(size=9))

Hadley Wickham

unread,
Jun 3, 2010, 7:46:04 AM6/3/10
to Nick S, ggplot2
Hi Nick,

Both scales work fine for me. Do you have the latest version of ggplot2?

Hadley

Nick S

unread,
Jun 3, 2010, 12:44:06 PM6/3/10
to ggplot2
I updated all packages...ggplot2 was not on the list requiring an
update. I'm running R v. 2.11.

I tried closing R...re-loading the data...and re-plotting but with the
same result. scale_colour_manual results in empty boxes in the legend.

Any other ideas?

On Jun 3, 4:46 am, Hadley Wickham <had...@rice.edu> wrote:
> Hi Nick,
>

Erik Iverson

unread,
Jun 3, 2010, 2:11:44 PM6/3/10
to Nick S, ggplot2

Nick S wrote:
> I updated all packages...ggplot2 was not on the list requiring an
> update. I'm running R v. 2.11.

R 2.11 is good. But the problem is almost surely caused by your
absolutely ancient version of ggplot2. If I recall, that must have been
one of the first releases of the package! Hadley I'm sure can help,
but there's a chance that maybe you didn't install the package from CRAN
even, so it's not finding the most up-to-date version.

What happens when you simply

> install.packages("ggplot2")

Nick S

unread,
Jun 3, 2010, 2:41:02 PM6/3/10
to ggplot2
Perhaps my previous post was a bit unclear...I do have the latest
version of ggplot2 (0.8.7) loaded from CRAN. When I updated all
packages from the menu...ggplot2 wasn't listed as needing an
update...which lead me to believe it was up-to date. I have since re-
loaded ggplot2 as you suggested and am still having the same issue.

Here's the output of sesssionInfo()
R version 2.11.0 (2010-04-22)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252
LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] grid stats graphics grDevices utils datasets
methods base

other attached packages:
[1] RODBC_1.3-1 TTR_0.20-2 xts_0.7-1 zoo_1.6-3
ggplot2_0.8.7 digest_0.4.2 reshape_0.8.3
[8] plyr_0.1.9 proto_0.3-8

loaded via a namespace (and not attached):
[1] lattice_0.18-5 RColorBrewer_1.0-2 tools_2.11.0

Erik Iverson

unread,
Jun 3, 2010, 2:46:00 PM6/3/10
to Nick S, ggplot2

Nick S wrote:
> Perhaps my previous post was a bit unclear...I do have the latest
> version of ggplot2 (0.8.7) loaded from CRAN. When I updated all
> packages from the menu...ggplot2 wasn't listed as needing an
> update...which lead me to believe it was up-to date. I have since re-
> loaded ggplot2 as you suggested and am still having the same issue.

Ok, odd! And what about traceback() results after the error?

fernando

unread,
Jun 3, 2010, 2:52:08 PM6/3/10
to Nick S, ggp...@googlegroups.com
Hi all,

I see the same as Nick, the point is including alpha and only affects the
line (simplified code bellow). Can be a OS issue?

library(ggplot2)
df <- data.frame(x = c(1, 2), y = c(1, 2), f = c("a", "a"))
qplot(x = x, y = y, colour = f, data = df) +
geom_line() +
scale_colour_manual(values = alpha("red", 0.99))

qplot(x = x, y = y, colour = f, data = df) +
geom_line() +
scale_colour_manual(values = "red")


R version 2.11.1 (2010-05-31)
x86_64-pc-mingw32

locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252

attached base packages:
[1] grid stats graphics grDevices utils datasets methods

[8] base

other attached packages:
[1] ggplot2_0.8.7 digest_0.4.2 reshape_0.8.3 plyr_0.1.9 proto_0.3-8

loaded via a namespace (and not attached):

[1] tools_2.11.1


-----Mensaje original-----
De: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] En nombre de
Nick S
Enviado el: jueves, 03 de junio de 2010 20:41
Para: ggplot2
Asunto: Re: scale_colour_manual issues

--

fernando

unread,
Jun 3, 2010, 3:31:47 PM6/3/10
to Nick S, ggplot2
Hi again,

I realized that when you save the graph the legend looks correct ... the
line does not appear on screen within R ... no idea what can be the reason
for this

library(ggplot2)

df <- data.frame(x = c(1, 2), y = c(1, 2), f = c("a", "a"))

pdf("deleteme.pdf")


qplot(x = x, y = y, colour = f, data = df) +
geom_line() +

scale_colour_manual(values = alpha("red", 0.6))
dev.off()


-----Mensaje original-----
De: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] En nombre de
Nick S
Enviado el: jueves, 03 de junio de 2010 20:41
Para: ggplot2
Asunto: Re: scale_colour_manual issues

Perhaps my previous post was a bit unclear...I do have the latest

--

Nick S

unread,
Jun 3, 2010, 4:41:35 PM6/3/10
to ggplot2
Thanks for pointing that out Fernando.

It definitely has something to do with the alpha setting. When I
remove this...the scale_colour_manual functions as expected and
displays the colors in the legend.

I have not been able to reproduce your findings with saving the image
and having it correctly display the legend colors. If I copy and paste
the resulting image...or save it to a file...while using the
scale_colour_manual with an alpha argument...it still shows no color
in the legend.

Nick S

unread,
Jun 3, 2010, 4:45:40 PM6/3/10
to ggplot2
Correction...Fernando was correct in that the legend does display
correctly when saving as a .pdf file. Even though the legend is empty
within the R graphics window.

The legend stays empty while trying to save the images as .png, .bmp,
or .jpg.

fernando

unread,
Jun 3, 2010, 5:30:11 PM6/3/10
to Nick S, ggplot2
Hi Nick,

For bitmap devices it works if the resolution is increased.

library(ggplot2)

df <- data.frame(x = c(1, 2), y = c(1, 2), f = c("a", "a"))

png("deleteme.png", width = 7, height = 7, unit = "in", res = 600)


qplot(x = x, y = y, colour = f, data = df) +
geom_line() +
scale_colour_manual(values = alpha("red", 0.6))
dev.off()


Hope this helps,
fernando


-----Mensaje original-----
De: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] En nombre de
Nick S

Enviado el: jueves, 03 de junio de 2010 22:46


Para: ggplot2
Asunto: Re: scale_colour_manual issues

Correction...Fernando was correct in that the legend does display

--

Reply all
Reply to author
Forward
0 new messages