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:
Dear All,
There is something I don't understand fundamentally about handling geocoords 
with vwlines, as the axample below may illustrate.
vwlines seems to require values somewhere between 0 and 1 as shares of the plot 
length and width, but obviously that's not the complete story: Point (1,1) is 
slightly outside.
Which spacial framework does vwlines employ?
How do I have to transform geoocoords to fit them into vwline?
Thank you in advance!
Yours, Ferri




library(rnaturalearth)
library(grid)
library(vwline)
# Install vwline via:
#library(devtools); install_github("pmur002/vwline/pkg@v0.1")
#mittex<--59.75#central meridian
#mittey<--62.316667#central latitude
mittex<--60.5617;mittey<--62.9832#Whalers Bay
#mittex<-120;mittey<-0#Sulawesi
band<-2#halve edge length of the depicted square, in degrees
map<-ne_countries(scale=10)#the source map
if(require(sp)){plot(map,ylim=c(mittey-band,mittey+band),xlim=c(mittex-band,mittex+band))}#plot
 the map
X<-c(-1,-1,-1,0,0,0,1,1,1)
Y<-c(-1,0,1,-1,0,1,-1,0,1)
points(mittex+X*band,mittey+Y*band,col="red")#The map does NOT end at xlim and 
ylim
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 vwlines miss the central dot; (1,1) is outside the plot

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to