Learn R Programming

lavaan (version 0.7-2)

lav_plotinfo_svgcode: Creates code to show a diagram in svg format

Description

Creates svg code to show a diagram of the model.

Usage

lav_plotinfo_svgcode(plotinfo,
                     outfile = "",
                     sloped_labels = TRUE,
                     standalone = FALSE,
                     stroke_width = 2L,
                     font_size = 20L,
                     idx_font_size = 15L,
                     dy = 5L,
                     mlovcolors = c("lightgreen", "lightblue"),
                     lightness= 1,
                     font_family = "Latin Modern Math, arial, Arial, sans",
                     italic = TRUE,
                     auto_subscript = TRUE
                     )

Value

NULL (invisible)

Arguments

plotinfo

A plotinfo structure as returned from lav_plotinfo_positions.

outfile

A connection or a character string, the file to store the code.

sloped_labels

logical, sloped labels for the edges.

standalone

logical, should code be added to produce an html file with the svg embedded in it? If FALSE (the default), the outfile (if specified) must have the file extension 'svg'; if TRUE, the file extension must be 'htm' or 'html'.

stroke_width

Value for stroke-width parameter in svg.

font_size

An integer specifying the normal font size to use.

idx_font_size

An integer specifying the font size to use for a subscript.

dy

An integer specifying the distance by which to move the baseline of the subscript.

mlovcolors

Array of two colors for distinguishing ov nodes with the same name across the levels of a multilevel model.

lightness

A scalar factor to modify the distances between nodes.

font_family

Fonts to be tried for rendering the labels. The first one, Latin Modern Math, is close to the default font used in tikz for mathematical expressions and can be downloaded from CTAN.

italic

Should labels be in an italic font? If FALSE, the labels are shown in mathrm font.

auto_subscript

Logical, see lav_label_code.

See Also

lav_plotinfo_positions

Examples

Run this code
model <- 'alpha  =~ x1 + x2 + x3       # latent variable
          beta <~ x4 + x5 + x6         # composite
          gamma =~ x7 + x8 + x9        # latent variable
          Xi =~ x10 + x11 + x12 + x13  # latent variable
          # regressions
          Xi ~ v * alpha + t * beta + 1
          alpha ~ yy * Theta1 + tt * beta + ss * gamma
          '
test <- lav_model_plotinfo(model)
test <- lav_plotinfo_positions(test)
lav_plotinfo_svgcode(test) # no file given, so output to R console
modelml <- '
        level: 1
        fw =~ 1*y_1 + y_2 + y_3 + y_5
        level: 2
        fb =~ 1*y_1 + y_2 + y_3 + y_4
        y_2 ~~ cv24 * y_4
  '
testml <- lav_model_plotinfo(modelml)
testml <- lav_plotinfo_positions(testml)
# in the line hereunder no file is given, so output to R console
lav_plotinfo_svgcode(testml, sloped_labels = FALSE, standalone = TRUE,
            auto_subscript = FALSE)
if (FALSE) {
# example creating html file with the above diagrams
zz <- file("demosvg.html", open="w")
writeLines(c(
  '',
  '',
  '',
  'SVG diagrams created by lav_plot R package'),
  zz)
lav_plotinfo_svgcode(test, outfile = "temp.svg")
tmp <- readLines("tmp.svg")
writeLines(tmp, zz)
writeLines("", zz)
lav_plotinfo_svgcode(testml, outfile = "temp.svg", sloped_labels = FALSE,
             standalone = TRUE)
tmp <- readLines("tmp.svg")
writeLines(tmp, zz)
writeLines(c("", ""), zz)
close(zz)
browseURL("demosvg.html")
}

Run the code above in your browser using DataLab