Learn R Programming

gridSVG (version 1.5-0)

Coordinate Conversion Functions: Functions for using an imported coordinate system

Description

These functions convert between different units. The conversion occurs within viewports unknown to grid, but imported to R via gridSVGCoords.

Usage

viewportConvertX(vpname, x, from, to = "svg") viewportConvertY(vpname, x, from, to = "svg") viewportConvertPos(vpname, x, y, from, to = "svg") viewportConvertWidth(vpname, x, from, to) viewportConvertHeight(vpname, x, from, to) viewportConvertDim(vpname, w, h, from, to)

Arguments

vpname
The name of the viewport that the unit belongs within.
x, y, w, h
The size of the unit in from units.
from
The type of unit that x is.
to
The unit that x is being converted to.

Value

A numeric vector containing a single value, the value of the new unit, or a list with components x and y for viewportConvertPos(), or a list with components w and h for viewportConvertDim().In the case of the viewportConvertX and viewportConvertY functions, we always return a value that is in terms of SVG pixels.

Details

Although grid has conversion functions available, it only converts units relative to the current viewport. After writing out to SVG, we no longer have actual grid viewports to convert units within.

These functions are designed so that once coordinate information is loaded into gridSVG via gridSVGCoords, we can translate units within each of these viewports. Note: this requires that a gridSVG plot has had viewport information exported.

These functions can be used in much the same way as grid's unit conversion functions, the only difference being that we have a new unit, svg, which represents the size of a unit in SVG pixels.

The viewportConvertPos() and viewportConvertDim() functions are for use with a viewport that has a non-zero rotation (both viewportConvertX() and viewportConvertY() will fail in that situation and viewportConvertWidth() and viewportConvertHeight() will give a not very useful answer).