A spice_plot is one rawfile plot: a set of named vectors of the
same length (one per circuit variable) sharing a scale (time,
frequency, the swept source of a .dc, ...). It is a list with
label: the plot's name within its result (seespice_run());plotname,title,date: the rawfile header fields;scale: the name of the scale vector, orNAfor plots without one (operating point,.tf,.pz, DC.sens, integrated noise);variables: a tibble with thenameandtype("voltage","current","time","frequency", ...) of every vector;values: a named list of the vectors, double for real plots and complex for complex ones (.ac,.pz, AC.sens,.disto);padded,commands,options,dimensions: the remaining rawfile header fields, kept so a plot writes back unchanged.
Long format
as_tibble() returns one row per point and non-scale variable, with
the scale repeated on every row:
plot(chr): the plot's label;point(int): the point index, from 1;scale_name(chr) andscale(dbl): the scale vector's name and value at that point (NAfor plots without a scale; the real part of the scale for complex plots, whose scale is real by construction);variable(chr) andtype(chr): the vector's name and type;for real plots,
value(dbl);for complex plots, instead of
value:reandim(dbl), and derived from themmag(the modulus),db(20 * log10(mag)) andphase(the argument, in degrees).
This is the long ("tidy") layout ggplot2 expects:
ggplot(df, aes(scale, value, colour = variable)) + geom_line().
Examples
res <- spice_run("rc\nvin 1 0 dc 0 ac 1\nr1 1 2 1k\nc1 2 0 1u\n.ac dec 5 10 10k\n.end")
ac <- spice_plots(res)[[1]]
ac
#> <spice_plot> AC Analysis: 4 variables x 16 points, complex, scale frequency
#> frequency <frequency> |.| in [10, 10000]
#> v(1) <voltage> |.| in [1, 1]
#> i(vin) <current> |.| in [6.271e-05, 0.0009999]
#> v(2) <voltage> |.| in [0.01591, 0.998]
tibble::as_tibble(ac)
#> # A tibble: 48 × 11
#> plot point scale_name scale variable type re im mag db phase
#> <chr> <int> <chr> <dbl> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 AC Analy… 1 frequency 10 v(1) volt… 1 0 1 0 0
#> 2 AC Analy… 2 frequency 15.8 v(1) volt… 1 0 1 0 0
#> 3 AC Analy… 3 frequency 25.1 v(1) volt… 1 0 1 0 0
#> 4 AC Analy… 4 frequency 39.8 v(1) volt… 1 0 1 0 0
#> 5 AC Analy… 5 frequency 63.1 v(1) volt… 1 0 1 0 0
#> 6 AC Analy… 6 frequency 100 v(1) volt… 1 0 1 0 0
#> 7 AC Analy… 7 frequency 158. v(1) volt… 1 0 1 0 0
#> 8 AC Analy… 8 frequency 251. v(1) volt… 1 0 1 0 0
#> 9 AC Analy… 9 frequency 398. v(1) volt… 1 0 1 0 0
#> 10 AC Analy… 10 frequency 631. v(1) volt… 1 0 1 0 0
#> # ℹ 38 more rows