[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-geo
Subject:    [R-sig-Geo] Custom legend with tmap
From:       Ulrike_Grömping <groemping () beuth-hochschule ! de>
Date:       2017-10-20 8:23:07
Message-ID: 60faa186-e8d9-1df2-bcf1-003936619ff5 () beuth-hochschule ! de
[Download RAW message or body]

Dear all,

I have a question on custom legends with tmap: the code below places 
small charts which have been previously stored as png files (file names 
in named character vector fns) on a map. The colors in these charts 
(stored in the vector farben) need a legend. Adding the legend with 
"tm_add_legend" works in the plot mode, but not in the view mode. The 
only way I found to get a legend in the view mode is to create a png 
with the legend included and place it on the legend with tm_markers 
(this is ignored in plot mode).

Is this indeed the only/best way, or (how) could I do this with less effort?

Best, Ulrike

#################
tm_shape(geo, is.master=TRUE) +
   tm_polygons(col = "grey", alpha=0, border.col 
="grey20",popup.vars=FALSE) +
   tm_symbols(shape="NAMEshort",
              shapes=tmap_icons(fns[sort(geo$NAMEshort)], width=96, 
height=96),
              shapes.legend=22,
              shapes.legend.fill=farben,
              shapes.labels=(10:40)/10,
              border.lwd=1,
              sizes.legend=c(.5, 1,3)*1e6,
              legend.shape.show = FALSE,
              legend.size.is.portrait = TRUE,
              id="NAMEshort",
              popup.vars = c("NAME_1"),
              icon.scale = 5, xmod="Xadj", ymod="Yadj") +
   tm_add_legend(type="fill",labels=(10:40)/10, col=farben)+
   tm_layout(main.title="Distribution of Abitur grades over time",
                title="2006 to 2015 from left to right",
                title.position = c("left","TOP"), title.size = 0.5,
                legend.outside.position = "right", legend.outside = TRUE,
             title.snap.to.legend = FALSE)+
tm_shape(legloc)+
   tm_markers(shape=tmap_icons("mosaiclegend.png",
          width=120, height=1800), size=0.1 )


-- 
##############################################
## Prof. Ulrike Groemping
## FB II
## Beuth University of Applied Sciences Berlin
##############################################
## prof.beuth-hochschule.de/groemping
## Phone: +49(0)30 4504 5127
## Fax:   +49(0)30 4504 66 5127
## Home office: +49(0)30 394 04 863
##############################################

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic