Skip to contents

The wide layout: one row per point, the plot's scale first (time, frequency, the swept source, ...) and then one column per variable, named as the variable. Columns of a complex plot (.ac) are complex vectors, so Mod(), Arg() and arithmetic between signals work directly. Use it when the computation is across variables (`v(out)` - `v(in)`); spice_tidy() is the layout 'ggplot2' wants.

Usage

spice_wide(result, plot = NULL, vars = NULL)

Arguments

result

A spice_result, or a spice_plot.

plot

The plot: a label, short name (see spice_tidy()) or position. Optional when the result has a single plot.

vars

Optional: names of the variables to keep, as in spice_tidy().

Value

A tibble with nrow = the plot's points.

Examples

res <- spice_run("rc\nvin 1 0 pulse(0 1)\nr1 1 2 1k\nc1 2 0 1u\n.tran 0.1m 5m\n.end")
w <- res |> spice_wide("tran")
w
#> # A tibble: 63 × 4
#>        time `v(1)`    `i(vin)`     `v(2)`
#>       <dbl>  <dbl>       <dbl>      <dbl>
#>  1 0          0     0          0         
#>  2 0.000001   0.01 -0.00000999 0.00000999
#>  3 0.000002   0.02 -0.0000200  0.0000250 
#>  4 0.000004   0.04 -0.0000399  0.0000849 
#>  5 0.000008   0.08 -0.0000797  0.000324  
#>  6 0.000016   0.16 -0.000159   0.00128   
#>  7 0.000032   0.32 -0.000315   0.00507   
#>  8 0.000064   0.64 -0.000620   0.0200    
#>  9 0.0001     1    -0.000952   0.0483    
#> 10 0.000106   1    -0.000946   0.0544    
#> # ℹ 53 more rows
# The voltage across r1
w$`v(1)` - w$`v(2)`
#>  [1] 0.000000000 0.009990010 0.019975027 0.039915133 0.079675924 0.158722115
#>  [7] 0.314931176 0.619959563 0.951652170 0.945600328 0.940128877 0.929280724
#> [13] 0.907958161 0.866766917 0.789886426 0.714689604 0.646651485 0.585090564
#> [19] 0.529390213 0.478992510 0.433392646 0.392133867 0.354802904 0.321025832
#> [25] 0.290464322 0.262812253 0.237792649 0.215154899 0.194672252 0.176139544
#> [31] 0.159371141 0.144199082 0.130471396 0.118050580 0.106812220 0.096643746
#> [37] 0.087443306 0.079118744 0.071586676 0.064771658 0.058605426 0.053026217
#> [43] 0.047978145 0.043410648 0.039277975 0.035538730 0.032155459 0.029094274
#> [49] 0.026324513 0.023818431 0.021550928 0.019499289 0.017642966 0.015963364
#> [55] 0.014443659 0.013068629 0.011824502 0.010698815 0.009680293 0.008758733
#> [61] 0.007924906 0.007486862 0.007073030