2

I'm trying to produce a map using either the tmap or ggplot2 packages and need to follow some internal design guidelines which state that legend keys should be spaced out and rectangular in shape.

I have tried tmap but the legend keys are square and stacked on top of each other without any spacing. I cannot figure out how to change the shape to rectangles and how to space out the keys.

In ggplot2, I get rectangles but the spacing seems to be fixed. Is there a way to space the keys out in ggplot2 (or tmap)?

theme_opts <- list(theme(panel.grid.minor = element_blank(),
                     panel.grid.major = element_blank(),
                     panel.background = element_blank(),
                     plot.background = element_blank(),
                     panel.border = element_blank(),
                     axis.line = element_blank(),
                     axis.text.x = element_blank(),
                     axis.text.y = element_blank(),
                     axis.ticks = element_blank(),
                     axis.title.x = element_blank(),
                     axis.title.y = element_blank(),
                     legend.position=c(0.015, 0.7),
                     legend.background = element_rect(fill=alpha("white", 0)),
                     legend.key.width = unit(1, "cm"),
                     legend.key.height = unit(0.2, "cm"),
                     legend.spacing.y = unit(1, "cm"),
                     legend.title = element_text(size=14,  family="Tahoma"),
                     legend.text = element_text(size=12,  family="Tahoma")))

p <- ggplot() +
  geom_sf(data = map_data_full, aes(fill = TransmissionClassification), size = 0.5, color = "gray10") +
  scale_fill_manual(values = colours, breaks = transmission_levels) +
  geom_sf(data = map_data_borders, fill = NA, size = 1, color = "black") +
  coord_sf(xlim = c(1405044, 7120890), ylim = c(1291822, 5218781)) +
  theme_opts 

This is how the legend looks:

This is how the legend looks

And this is what I would like:

And this is what I would like

Gakku
  • 337
  • 2
  • 8

0 Answers0