Get the right scale for plotting a map. While width must be defined, the according height is calculated

getDimensions(xlim, ylim, width = 10)

Arguments

xlim

Minimum and maximum longitude of the map

ylim

Minimum and maximum lattitude of the map

width

Numeric value defining the width of the plot (in inch)

Value

Named vector of two, containing the width (for x-axis dimension) and the height (for y-axis dimension).

Details

The ratio between width and height is directly based on the ratio between lonigtude and lattitude. In order to get the correct scale for the plot the margins need to be set to 0 (see example).

Examples

xlim <- c(13.18, 13.472)
ylim <- c(52.46, 52.57)
plotDim <- getDimensions(xlim = xlim, ylim = ylim, width = 10)
plotDim
#>     width    height 
#> 10.000000  6.182557 

dev.new(noRStudioGD = TRUE, width = plotDim[1], height = plotDim[2])
par(mar = c(0, 0, 0, 0)) # no margins outside of the plot
plot(x = xlim, y = ylim, type = "l")
text(x = mean(xlim), y = ylim[2],
     labels = "Correctly Scaled Line",
     pos = 1, cex = 3)