How do I set the tab for spatial lines in ggplot?

3

I'm plotting lines on polygons, but when I try to insert the legend the lines look bad, how do I adjust that?

Without the Legend

library("ggplot2")
ggplot(mapa_mg) + 
  aes(x=long, y=lat, group=group) +
  geom_polygon(fill = "white") +
  geom_path(color="grey50") +
  labs(y="latitude", x="longitude") +
  geom_polygon(data=mapa_rod, 
               mapping=aes(x=long, y=lat, group=group), 
               color = cores[mapa_rod$idcores],
               fill="transparent",
               size = 1) +
  coord_equal()

Withthecaption

library("ggplot2")
ggplot(mapa_mg) + 
  aes(x=long, y=lat, group=group) +
  geom_polygon(fill = "white") +
  geom_path(color="grey50") +
  labs(y="latitude", x="longitude") +
  geom_polygon(data=mapa_rod, 
               mapping=aes(x=long, y=lat, group=group), 
               color = cores[mapa_rod$idcores],
               fill="transparent",
               size = 1) +
  coord_equal()

    
asked by anonymous 08.07.2018 / 02:02

1 answer

1

Solution :

legenda1 = c("BR-040","BR-116","BR-262","BR-381")
cores = c('#d01c8b', 'yellow', '#e66101', 'blue')

library("ggplot2")
library('ggsn')
library("ggrepel")

ggplot(mapa_mg) +       
  aes(x=long, y=lat, group=group) +
  geom_polygon(fill = "white") +
  geom_path(color="grey50") +
  labs(y="latitude", x="longitude") +

  geom_path(data=mapa_rod, 
               mapping=aes(x=long, y=lat, group=group, color=factor(idcores)), size = 1) +
  scale_colour_manual(values = cores, labels = legenda1) +
  labs(color = 'Rodovia') +

  theme(legend.title = element_text(face = 'bold', size = 10)) +
  theme(legend.text = element_text(face = NULL, size = 9)) +
  theme(legend.background = element_rect(fill="white", size=.5, linetype="dotted")) +
  theme(legend.position=c(0.11, 0.15)) +

  ggsn::scalebar(mapa_mg, dist = 100, st.size=3, height=0.01, dd2km = TRUE, model = 'WGS84') +
  ggsn::north(mapa_mg, symbol = 16, scale = 0.15) +

  coord_equal()

    
09.07.2018 / 16:30