3

I have a crowded map I've generated using the tmap library, I've turned the legend off with the argument legend.show = FALSE in the tm_layout() function.

What I want to know is the following: is there a way to generate a legend for this map on its own? So that it could be a stand alone image?

(I'm sorry the code won't give you a map)

tm_borders()+
tm_shape(parks)+
  tm_polygons()+
tm_shape(houses)+
  tm_polygons()+
tm_shape(grid)+
    tm_polygons(col="n", style ="cont", palette="plasma",alpha = 0.5)+
tm_layout(legend.show=FALSE)  

EDIT: Yes. It's in the help file and it's this: argument legend.only = TRUE in the tm_layout() function.

  tm_borders()+
    tm_shape(parks)+
      tm_polygons()+
    tm_shape(houses)+
      tm_polygons()+
    tm_shape(grid)+
        tm_polygons(col="n", style ="cont", palette="plasma",alpha = 0.5)+
    tm_layout(legend.only= T)
lovalery
  • 4,524
  • 3
  • 14
  • 28
damo
  • 463
  • 4
  • 14

1 Answers1

6

EDIT: Yes. It's in the help file and it's this: legend.only

tm_borders()+
    tm_shape(parks)+
      tm_polygons()+
    tm_shape(houses)+
      tm_polygons()+
    tm_shape(grid)+
        tm_polygons(col="n", style ="cont", palette="plasma",alpha = 0.5)+
    tm_layout(legend.only= T)
damo
  • 463
  • 4
  • 14