First of all, thank you for the reproducible example.
Scales are one of the more difficult features of ggplot2 to master,
and a few things are going on here that you need to learn about:
(i) You can define labels in a separate vector or as labels in a
factor() statement; since you want expressions, the former is
advisable in this case.
(ii) When you map multiple aesthetics to the same variable and want
to use a single legend, you need to modify all legends with a suitable
scale_*() function, one for each aesthetic defined.
(iii) You can modify a title either by picking a suitable variable
name for the factor of interest (which will be the default legend
title) or you can change it manually inside a scale_*() function.
Here's a way to get what I think you want with the legend:
# Create a factor variable for treatment rather than a character
variable so that you can control the ordering of the levels:
melt.M2$treat <- factor(melt.M2$Treat, levels = c('2M0001', '2M0010', '2M0100'))
# Create a list of expressions that can be passed into the scale
functions as the labels = argument:
labls <- list(expression(paste('1', mu, 'M', sep = "")),
expression(paste('10', mu, 'M', sep = "")),
expression(paste('100', mu, 'M', sep = "")))
ggplot(data = melt.M2, aes(x = Time, y = value, color = treat, fill = treat)) +
stat_summary(fun.data="mean_cl_normal", geom="smooth", size=1, alpha=0.1) +
scale_x_continuous(limits = c(0, 48)) +
scale_color_manual('My title', breaks = levels(melt.M2$treat),
values = c('blue', 'green', 'orange'),
labels = labls) +
scale_fill_manual('My title', breaks = levels(melt.M2$treat),
values = c('blue', 'green', 'orange'),
labels = labls)
Notice that both scale_color_manual() and scale_fill_manual() needed
to be used in order for the two legends to merge. More specifically,
the two legends need the same title, the same breaks, the same values
and the same labels for the merger to take place.
You don't need guide_legend() here unless you want to change aspects
of the legend that are under its control, which are described on its
help page.
HTH,
Dennis
> --
> 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