Ploting correct colors with ggplot and geom_map
<p>I have this data frame called regional:</p>

<pre><code>                       id         Growth    interv  color
1              ALENTEJO CENTRAL   479.11  (475,500] yellow
2              ALENTEJO LITORAL   530.23 (525, Inf] green4
3                       ALGARVE   470.91  (450,475]    red
4                 ALTO ALENTEJO   499.72  (475,500] yellow
5                    ALTO MINHO   519.31  (500,525]  green
6                   ALTO TÂMEGA   460.50  (450,475]    red
7  ÁREA METROPOLITANA DE LISBOA   494.05  (475,500] yellow
8   ÁREA METROPOLITANA DO PORTO   497.15  (475,500] yellow
9                           AVE   484.41  (475,500] yellow
10               BAIXO ALENTEJO   461.79  (450,475]    red
11                  BEIRA BAIXA   511.19  (500,525]  green
12    BEIRAS E SERRA DA ESTRELA   503.52  (500,525]  green
13                       CÁVADO   486.08  (475,500] yellow
14                        DOURO   509.93  (500,525]  green
15              LEZÍRIA DO TEJO   514.67  (500,525]  green
16                   MÉDIO TEJO   504.39  (500,525]  green
17                        OESTE   488.85  (475,500] yellow
18                 R. A. AÇORES   461.74  (450,475]    red
19                R. A. MADEIRA   490.16  (475,500] yellow
20             REGIÃO DE AVEIRO   490.46  (475,500] yellow
21            REGIÃO DE COIMBRA   502.82  (500,525]  green
22             REGIÃO DE LEIRIA   507.60  (500,525]  green
23               TÂMEGA E SOUSA   452.97  (450,475]    red
24     TERRAS DE TRÁS-OS-MONTES   454.03  (450,475]    red
25             VISEU DÃO LAFÕES   514.99  (500,525]  green
</code></pre>

<p>and I am trying to plot a map with the colors in the last column (regional$color) with this code:</p>

<pre><code>niv_leg=c("&lt;450","]450; 475]", "]475;500]","]500; 525]", "&gt;525")
colors = c("red4", "red", "yellow", "green", "green4")

prtnutsiii = ggplot()+
  geom_polygon(data = mapaf, aes(x=long, y = lat, group = group), fill = NA, colour="darkgray", size=0.25)+
  coord_equal()

growth = prtnutsiii +
  geom_map(data = regional, map = mapaf, aes(map_id = id, fill =  color),colour="darkgray", size = 0.25) +
  theme(legend.title = element_blank())
  scale_fill_manual(values = colors,labels = niv_leg)
pisamathg + theme(legend.position = "left")
</code></pre>

<p>I get this map:
<a href="https://i.stack.imgur.com/h3ZRE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h3ZRE.jpg" alt="enter image description here"></a></p>

<p>But I am facing two problems and I can't figure them out:</p>

<ol>
<li>I only get 4 labels in the legend (they should be 5)</li>
<li>The colors are not ploted correctly at all for the different "id" regions...</li>
</ol>

<p>The "id" in the mapaf match the "id" in the regional dataframe so, I have no clue why it does not work... Any help will be appreciated.</p>

<p>P.S.: The shp file (mapaf) I am using is here: <a href="https://dl.dropboxusercontent.com/u/112525/mapaf.txt" rel="nofollow noreferrer">https://dl.dropboxusercontent.com/u/112525/mapaf.txt</a></p>

<p>This is the dput(regional):</p>

<pre><code>structure(list(id = c("ALENTEJO CENTRAL", "ALENTEJO LITORAL", 
"ALGARVE", "ALTO ALENTEJO", "ALTO MINHO", "ALTO TÂMEGA", "ÁREA METROPOLITANA DE LISBOA", 
"ÁREA METROPOLITANA DO PORTO", "AVE", "BAIXO ALENTEJO", "BEIRA BAIXA", 
"BEIRAS E SERRA DA ESTRELA", "CÁVADO", "DOURO", "LEZÍRIA DO TEJO", 
"MÉDIO TEJO", "OESTE", "R. A. AÇORES", "R. A. MADEIRA", "REGIÃO DE AVEIRO", 
"REGIÃO DE COIMBRA", "REGIÃO DE LEIRIA", "TÂMEGA E SOUSA", "TERRAS DE TRÁS-OS-MONTES", 
"VISEU DÃO LAFÕES"), MATHMEAN = c(479.11, 530.23, 470.91, 499.72, 
519.31, 460.5, 494.05, 497.15, 484.41, 461.79, 511.19, 503.52, 
486.08, 509.93, 514.67, 504.39, 488.85, 461.74, 490.16, 490.46, 
502.82, 507.6, 452.97, 454.03, 514.99), interv = structure(c(3L, 
5L, 2L, 3L, 4L, 2L, 3L, 3L, 3L, 2L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 
2L, 3L, 3L, 4L, 4L, 2L, 2L, 4L), .Label = c("[-Inf,450]", "(450,475]", 
"(475,500]", "(500,525]", "(525, Inf]"), class = "factor"), color = structure(c(3L, 
5L, 2L, 3L, 4L, 2L, 3L, 3L, 3L, 2L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 
2L, 3L, 3L, 4L, 4L, 2L, 2L, 4L), .Label = c("red4", "red", "yellow", 
"green", "green4"), class = "factor")), .Names = c("id", "MATHMEAN", 
"interv", "color"), row.names = c(NA, -25L), class = "data.frame")
</code></pre>