Andres Gonzalez
Andres Gonzalez

Reputation: 329

Put legend horizontally in tmaps

I'm doing a map using data("World") and I want to show the legend in the bottom and horizontally. Currently, my map is something like this:

enter image description here

I want something like this: enter image description here

Here is my code:

tm_shape(mundo)+
  tm_borders() + 
  tm_fill("total_vaccinations_per_hundred",
              palette = "Blues",
          title = "",
          breaks = c(0, 0.1, 0.3, 1, 3, 10, 30, 100, 300),
          style = "cont")+ 
  tm_layout(main.title = "Dosis administradas de vacuna contra el COVID-19 por cada 100 personas", 
            main.title.position = "center", main.title.fontface = "bold")

Thanks in advance!

Upvotes: 3

Views: 1684

Answers (1)

Peter
Peter

Reputation: 12699

Does this get you where you want to be?

library(tmap)

data("World")

tm_shape(World)+
  tm_borders()+ 
  tm_fill("HPI",
          palette = "Blues",
          title = "",
          breaks = c(0, 0.1, 0.3, 1, 3, 10, 30, 100, 300),
          style = "cont",
          legend.is.portrait = FALSE)+
  tm_layout(legend.outside.position = "bottom",
            legend.outside.size = 0.35,
            legend.outside = TRUE)

Created on 2021-04-07 by the reprex package (v1.0.0)

Upvotes: 4

Related Questions