Hi:
The problem is that you use different sets of labels in each
scale_*_manual. To get all of the scales to merge into one, you need
to have the same title, same breaks and same labels for the legend.
This gets you a single legend:
ggplot(data = df, aes(x = year, y = total, colour = treatment,
linetype=treatment)) +
geom_point(aes(shape = treatment)) +
facet_wrap(~country) +
scale_colour_manual(breaks=c('A','B','C','D','E','F','G'),
values=c('A'='black','B'='black', 'C'='grey',
'D'='grey','E'='red','F'='grey', 'G'='red'),
labels=c('A: Line 1','B: Line 2','C: Line3','D: Line 4',
'E: Line 5','F: Line 6','G: Line 7')) +
scale_linetype_manual(breaks=c('A','B','C','D','E','F','G'),
values=c('A'='solid','B'='dotted', 'C'='solid','D'='dashed',
'E'='dashed','F'='dotted', 'G'='dotted'),
labels=c('A: Line 1','B: Line 2','C: Line3','D: Line 4',
'E: Line 5','F: Line 6','G: Line 7')) +
scale_shape_manual(breaks=c('A','B','C','D','E','F','G'),
labels=c('A: Line 1','B: Line 2','C: Line3','D: Line 4',
'E: Line 5','F: Line 6','G: Line 7'),
values = c(0, 1, 2, 3, 4, 5, 6)) +
theme_bw() +
geom_abline(aes(intercept = Intercept, slope = Slope,
colour = treatment, linetype=treatment),
data = lines)
In your original, you had different line numbers as labels in
scale_colour_manual() and scale_shape_manual(). If you want to
maintain that, then you'll have to have separate legends for color and
shape.
HTH,
Dennis
On Tue, Nov 8, 2011 at 11:22 AM, Sigrid s.stene...@gmail.com wrote:
Hi there,
I am having a little problem with combining three scale_manual commands in a
facet plot. I am not able to combine the three different characteristics,
instead ending up with three different descriptions next to the graph for
the same geom. I would like to see two separate labels (not three); one
describing lines 1-7 and the other 8-14. For each of the treatments (A-B) I
want a combination of color, line type and symbol. How do I do this?
Here are my codes (Feel free to modify the example to make it easier to work
with. I was not able to do this while keeping the problem I wanted help
with)
df -structure(list(year = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1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3L,
3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 2L,
2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L,
7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L,
6L, 6L, 6L, 7L, 7L, 7L), .Label = c(A, B, C, D, E,
F, G), class = factor), total = c(135L, 118L, 121L, 64L,
53L, 49L, 178L, 123L, 128L, 127L, 62L, 129L, 126L, 99L, 183L,
45L, 57L, 45L, 72L, 30L, 71L, 123L, 89L, 102L, 60L, 44L, 59L,
124L, 145L, 126L, 103L, 67L, 97L, 66L, 76L, 108L, 36L, 48L, 41L,
69L, 47L, 57L, 167L, 136L, 176L, 85L, 36L, 82L, 222L, 149L, 171L,
145L, 122L, 192L, 136L, 164L, 154L, 46L, 57L, 57L, 70L, 55L,
102L, 111L, 152L, 204L, 41L, 46L, 103L, 156L, 148L, 155L, 103L,
124L, 176L, 111L, 142L, 187L, 43L, 52L, 75L, 64L, 91L, 78L, 196L,
314L, 265L, 44L, 39L, 98L, 197L, 273L, 274L, 89L, 91L, 74L, 91L,
112L, 98L, 140L, 90L, 121L, 120L, 161L, 83L, 230L, 266L, 282L,
35L, 53L, 57L, 315L, 332L, 202L, 90L, 79L, 89L, 67L, 116L, 109L,
44L, 68L, 75L, 29L, 52L, 52L, 253L, 203L, 87L, 105L, 234L, 152L,
247L, 243L, 144L, 167L, 165L, 95L, 300L, 128L, 125L, 84L, 183L,
88L, 153L, 185L, 175L, 226L, 216L, 118L, 118L, 94L, 224L, 259L,
176L, 175L, 147L, 197L, 141L, 176L, 187L, 87L, 92L, 148L, 86L,
139L, 122L), country = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L,