Skip to content
Prev 377408 / 398502 Next

Interplay rnaturalearth, vwline

There are a couple of important concepts in play here:

1.
You are drawing the map with the 'graphics' system, but 'vwline' works 
in the 'grid' system.

2.
In the 'grid' system, you can work with lots of different coordinate 
systems.  The default is usually "npc" (which is 0 to 1), but you can 
choose to use others, for example, "native" draws relative to scales on 
the axes (roughly speaking).

If you change the last two lines of your example to the following, it 
might look more like what you expect (?) ...

## Convert the 'graphics' map to a 'grid' equivalent
library(gridGraphics)
grid.echo()
## Navigate to the 'grid' viewport that corresponds to the map
## region
downViewport("graphics-plot-1")
## Draw lines between the corners of the map region
grid.vwline(c(0,1), c(0,1), c(1/1000,1/1000))
grid.vwline(c(0,1), c(1,0), c(1/1000,1/1000))

The next code provides an example of drawing relative to the map 
coordinates (NOTE the use of "native" units) ...

## Navigate to the 'grid' viewport that corresponds to the map
## coordinate system
downViewport("graphics-window-1-1")
## Draw lines relative to the map coordinate system
grid.vwline(mittex + X*band, mittey + Y*band, default.units="native",
             unit(1:9, "mm"), gp=gpar(fill=rgb(1,0,0,.2)))


Hope that helps

Paul
On 14/11/18 6:02 AM, Ferri Leberl wrote: