title: Is it possible to have a subset of variables in a ggplot2 legend with facets?
body: <p>I have a plot with three groups. I have used facets to get the graph as I want, and I managed to unite the colour and shape into a single legend (as shown below). The problem, however, is that the legend contains all the six variable names, whereas having only two suffice.</p>
  
  <p>Here is my current output:
  <img src="https://i.stack.imgur.com/6DwKG.png" alt="enter image description here"></p>
  
  <p>Is it possible to obtain a legend with only two keys: "Divergence" and "% of Women" (instead of the current 6 keys) ?</p>
  
  <p>Here is the code used to produce the plot:</p>
  
  <pre><code>years &lt;- c('97','98','99','00','01','02','03','04','05','06','07','08','09','10','11')
  years &lt;- factor(years, levels=years, ordered=T)             
  phy_ratio &lt;- c(0.124516129032258, 0.11545988258317,  0.115190784737221, 0.120919881305638, 0.132198952879581, 0.147636363636364, 0.171033478893741, 0.155994550408719, 0.150121065375303, 0.182989690721649, 0.19466515323496,  0.194550408719346, 0.203811540497618, 0.214399152991001, 0.195157384987893)
  phy_kldiv &lt;- c(0.040955264723678, 0.001463273151143, 0.011790601776013, 0.00575319295143,  0.003434619043043, 0.001405575036774, 0.012395353183334, 0.002864433864471, 0.006622155735437, 0.074859543690491, 0.013087320475828, 0.023585193439178, 0.08866626868359,  0.07879809266254,  0.04536730602564)
  mat_ratio &lt;- c(0.236086175942549,  0.253846153846154, 0.256481481481481, 0.246901811248808, 0.273267326732673, 0.290076335877863, 0.265861027190332, 0.283457249070632, 0.27098919368246,  0.296156744536549, 0.289834174477289, 0.309506790564689, 0.311612903225806, 0.293710691823899, 0.286604361370716)
  mat_kldiv &lt;- c(0.024935971694693,  0.012778283551598, 0.019350970177576, 0.00988763992456,  0.008284622131022, 0.014700010603506, 0.015235482499119, 0.023914776035294, 0.018878559121565, 0.073688344207842, 0.042784809873074, 0.052110805729914, 0.072367460713338, 0.017494663842138, 0.019605349179071)
  psc_ratio &lt;- c(0, 0, 0, 0.370182555780933, 0.325227963525836, 0.416528925619835, 0.379727685325265, 0.333901192504259, 0.396440129449838, 0.357142857142857, 0.412265758091993, 0.415605095541401, 0, 0, 0)
  psc_kldiv &lt;- c(0, 0, 0, 0.156958669813655, 0.02319115435268,  0.019560312744745, 0.142939013816555, 0.050687092785045, 0.030903744617805, 0.021234599637716, 0.049901381314152, 0.176930275568253, 0, 0, 0)
  df &lt;- data.frame("Years"=years,
                   '% of Women (Physics)'=phy_ratio,
                   'Divergence (Physics)'=phy_kldiv,
                   '% of Women (Maths)'=mat_ratio,
                   'Divergence (Maths)'=mat_kldiv,
                   '% of Women (Polit. Sci.)'=psc_ratio,
                   'Divergence (Polit. Sci.)'=psc_kldiv,
                   check.names=F)
  df.m &lt;- melt(df, id="Years")
  df.m &lt;- transform(df.m, facet=ifelse(variable %in% c('% of Women (Physics)',
                                                        'Divergence (Physics)'), 'phy',
                                   ifelse(variable %in% c('% of Women (Maths)',
                                                               'Divergence (Maths)'),'mat',
                                          ifelse(variable %in% c('% of Women (Polit. Sci.)', 'Divergence (Polit. Sci.)'), 'psc', 'mat'))))
  g &lt;- ggplot(df.m, aes(group=1, x=Years, y=value, colour=variable, shape=variable))
  g &lt;- g + scale_colour_manual(name='',
                               labels=c('Phy: % of Women', 'Phy: Divergence',
                                        'Maths: % of Women', 'Maths: Divergence',
                                        'Polit. Sci: % of Women', 'Polit. Sci: Divergence'),
                               values=c('chartreuse4', 'deepskyblue3', 'chartreuse4', 'deepskyblue3', 'chartreuse4', 'deepskyblue3'))
  g &lt;- g + scale_shape_manual(name='',
                              labels=c('Phy: % of Women', 'Phy: Divergence',
                                       'Maths: % of Women', 'Maths: Divergence',
                                       'Polit. Sci: % of Women', 'Polit. Sci: Divergence'),
                              values=c(19, 17, 19, 17, 19, 17))
  g &lt;- g + geom_point(aes(colour=variable), size=3)
  g &lt;- g + facet_grid(.~facet)
  g &lt;- g + coord_cartesian(ylim=(c(0.0,0.45)))
  g &lt;- g + scale_x_discrete("", expand=c(0.01, 0.01))
  g &lt;- g + scale_y_continuous(name="")
  g &lt;- g + guides(colour=guide_legend(title='', ncol=2, keywidth=unit(2,'lines')))
  g &lt;- g + theme(legend.position=c(0.33,0.72),
                 legend.justification=c(0,0),
                 legend.key=element_blank(),
                 legend.background=element_rect(colour='black', fill='transparent'),
                 legend.text=element_text(size=12),
                 panel.grid.minor = element_blank(),
                 panel.margin=unit(1, 'lines'),
                 axis.text=element_text(size=12,color="black"),
                 axis.title=element_text(size=16),
                 strip.text.y = element_text(size = 14))
  </code></pre>