---
title: "Scaling Issues"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Scaling Issues}
%\VignetteEngine{knitr::rmarkdown}
\usepackage[utf8]{inputenc}
---
## Scaling SVG outputs
The SVG files produced by svglite do not include `width` and `height`
properties. This is a deliberate choice intended to make it easier to
fit fluidly a SVG figure to its enclosing container. The scaling
straightforward but requires some understanding of the `viewBox` SVG
attribute which is included in all SVGs produced by svglite. This
property defines the aspect ratio of the plot (as well as a *user
coordinate system*, see next section).
### Fluid scaling
The viewBox is determined by the `width` and `height` arguments of
svglite's device functions (with 10'' x 8'' the default). Although
those dimensions are supplied in inches, the viewBox's user coordinate
system is completely unit agnostic. The main effect is thus to
determine an aspect ratio. Since dimensions are not provided, the
dimensions of the enclosing container are used instead and the SVG is
rescaled to fit the container (although Internet Explorer currently
requires some CSS tricks to get this behaviour, see
).
Aspect ratio is preserved by default when the figure is scaled up or
down. The details of how the aspect ratio is preserved can be adjusted
in multiple ways via the `preserveAspectRatio` attribute. See
for more
information about this property.
Other useful resource:
### Natural scaling
Another strategy is needed in order to scale the figure to make the
text within the SVG consistent with the text in the surrounding web
page. That could be useful, for instance, to create a consistent
appearance in an HTML presentation. Since the user coordinate system
defined by the viewBox is unitless, we need to map the figure to its
natural dimensions. This will ensure a correspondence between the
scale of the figure and that of the web page.
As mentioned above, the natural scale of svglite's figures is in
points and is determined by the `width` and `height` arguments that
you supply to the device functions (10'' x 8'' being the
default). Although those dimensions are specified in inches, the
coordinate system is scaled in points. Counting 72 points per inch,
the default SVG surface is thus 720 x 576 pt. Note that the CSS standard
defines 12pt to be equal to 16px, the default size of text in most
browsers. Since 12pt is the default text size in svglite as well, a
SVG scaled to its natural dimensions will appear seamless with web
text of 16px. If the text in your web page has another size, you will
have to compute a scale factor and adjust the dimensions of the SVG
accordingly.
To sum up, displaying a plot according to its natural dimensions
requires providing the user agent with information about what the
lengths defined within the SVG actually mean. There are several ways
to achieve this. First you can edit the SVG and enclose it in another
pair of `