Skip to content

Commit

Permalink
added attr outside option
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Apr 29, 2016
1 parent dec44a5 commit 13683ab
Show file tree
Hide file tree
Showing 14 changed files with 833 additions and 707 deletions.
2 changes: 1 addition & 1 deletion examples/tm_scale_bar.R
Expand Up @@ -6,7 +6,7 @@ qtm(NLD_muni, theme = "NLD") + tm_scale_bar(position=c("left", "bottom"))
data(Europe)
tm_shape(Europe, unit = "miles", unit.size=1609) +
tm_polygons() +
tm_scale_bar(position = c(.5, "BOTTOM"))
tm_scale_bar() + tm_layout(attr.outside = TRUE)

# restore current mode
tmap_mode(current.mode)
15 changes: 12 additions & 3 deletions pkg/R/gridplot.R
@@ -1,4 +1,4 @@
gridplot <- function(gmeta, fun, nx, gps, shps, dasp, sasp, inner.margins.new, legend_pos, gp_leg) {
gridplot <- function(gmeta, fun, nx, gps, shps, dasp, sasp, inner.margins.new, legend_pos, gp_leg, gp_attr) {
mfrow <- gmeta$nrow
mfcol <- gmeta$ncol

Expand Down Expand Up @@ -74,7 +74,7 @@ gridplot <- function(gmeta, fun, nx, gps, shps, dasp, sasp, inner.margins.new, l
rep(gmeta$colrange, times=mfrow, length.out=ni), SIMPLIFY=FALSE)

## draw outside grid labels
treeGridLabels <- if (external_grid_labels) {
treeGridLabels <- if (external_grid_labels && gmeta$grid.show) {
mapply(function(i, rw, cl) {
if (multi_shapes) {
proj <- bbxproj[[i]]$proj
Expand Down Expand Up @@ -133,7 +133,16 @@ gridplot <- function(gmeta, fun, nx, gps, shps, dasp, sasp, inner.margins.new, l
legPanel <- NULL
}

tree <- gTree(children=do.call("gList", c(list(grobBG, grobBG2, grobFacetBG), treeGridLabels, treeMults, rowPanels, colPanels, legPanel)), vp=vpGrid)
## draw attributes legend
if (!is.null(gp_attr)) {
attrPanel <- gList(cellplot(gmeta$attry, gmeta$attrx, e=do.call(fun, args=list(1, gp_attr, shps, dasp, sasp, inner.margins.new, legend_pos, nx>1)), name = "outside_attr"))
} else {
attrPanel <- NULL
}



tree <- gTree(children=do.call("gList", c(list(grobBG, grobBG2, grobFacetBG), treeGridLabels, treeMults, rowPanels, colPanels, legPanel, attrPanel)), vp=vpGrid)
grid.draw(tree)
})
upViewport()
Expand Down

0 comments on commit 13683ab

Please sign in to comment.