Get Figure Dimensions

Description

Give the dimension of a map figure to be exported in raster of vector format.
Output dimension are based on a Spatial*DataFrame dimension ratio, the margins of the figure, a targeted width or height of the figure and its resolution.

Usage

1
getFigDim(spdf, width = NULL, height = NULL, mar = par("mar"), res = 72)

Arguments

spdf

a Spatial*DataFrame.

width

width of the figure (in pixels), either width or height must be set.

height

heigth of the figure (in pixels), either width or height must be set.

mar

a numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot (see par).

res

the nominal resolution in ppi which will be recorded in the bitmap file.

Details

The function can be used to export vector or raster files (see examples).

Value

A vector of width and height in pixels is returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 
data("nuts2006")
spdf <- nuts0.spdf[nuts0.spdf$id=="IT",]

## PNG export
# get figure dimension
sizes <- getFigDim(spdf = spdf, width = 450, mar = c(0,0,1.2,0))
# export the map
png(filename = "Italy.png", width = sizes[1], height = sizes[2])
par(mar = c(0,0,1.2,0))
plot(spdf, col = NA, border=NA, bg = "#A6CAE0")
plot(world.spdf, col = "#E3DEBF", border = NA, add = TRUE)
plot(spdf, col = "#D1914D", border = "white", add = TRUE)
layoutLayer(title = "Map of Italy")
dev.off()

## PDF export
# get figure dimension
sizes <- getFigDim(spdf = spdf, width = 450, mar = c(1,1,2.2,1))
# export the map
pdf(file = "Italy.pdf", width = sizes[1]/72, height = sizes[2]/72)
par(mar = c(1,1,2.2,1))
plot(spdf, col = NA, border = NA, bg = "#A6CAE0")
plot(world.spdf, col = "#E3DEBF", border = NA, add = TRUE)
plot(spdf, col = "#D1914D", border = "white", add = TRUE)
layoutLayer(title = "Map of Italy")
dev.off()

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.