damo
damo

Reputation: 473

Plotting legend only in tmap

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)

Upvotes: 3

Views: 1166

Answers (1)

damo
damo

Reputation: 473

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)

Upvotes: 6

Related Questions