1

I would like to create a table with Coronavirus case counts for the state of Utah in the United States. I have a table with two columns: a date column and a column of total new cases for that day in my state. I would like Org to generate a third column that is a cumulative sum of all the previous case counts.

The output should look like this:

  |------------------+----+-----|
  | <2020-02-27 Thu> |  0 |   0 |
  | <2020-02-28 Fri> |  1 |   1 |
  | <2020-02-29 Sat> |  0 |   1 |
  | <2020-03-01 Sun> |  0 |   1 |
  | <2020-03-02 Mon> |  0 |   1 |
  | <2020-03-03 Tue> |  0 |   1 |
  | <2020-03-04 Wed> |  1 |   2 |
  | <2020-03-05 Thu> |  1 |   3 |
  | <2020-03-06 Fri> |  2 |   5 |
  | <2020-03-07 Sat> |  2 |   7 |
  | <2020-03-08 Sun> |  1 |   8 |
  | <2020-03-09 Mon> |  0 |   8 |
  | <2020-03-10 Tue> |  1 |   9 |
  | <2020-03-11 Wed> |  3 |  12 |
  | <2020-03-12 Thu> |  5 |  17 |
  | <2020-03-13 Fri> |  6 |  23 |
  | <2020-03-14 Sat> | 13 |  36 |
  | <2020-03-15 Sun> | 11 |  47 |
  | <2020-03-16 Mon> |  8 |  55 |
  | <2020-03-17 Tue> | 22 |  77 |
  | <2020-03-18 Wed> | 13 |  90 |
  | <2020-03-19 Thu> | 31 | 121 |
  | <2020-03-20 Fri> | 27 | 148 |
  | <2020-03-21 Sat> | 33 | 181 |
  | <2020-03-22 Sun> | 69 | 250 |
  |                  |    |     |
  |------------------+----+-----|
  #+TBLFM: $3=$2+@-1$3

But when I run C-u C-c * to recompute the entire table line by line, that generates the error:

row descriptor -1 leads outside table

Also, I would appreciate if anyone knows how to plot this data using gnuplot or perhaps just an ascii plot.

3

You can use vsum for the cumulative sum as shown in the following Org code.

There are two options for plotting the data with gnuplot. You can either use a meta comment line #+PLOT: or a gnuplot source block. Both cases are shown in the following example.

You have to type [[file:coronaMeta.png]] yourself in the case of the meta line. The source block adds itself a #+RESULTS: and a line with the file link.

#+NAME: corona
#+PLOT: file:"coronaMeta.png" title:"Corona Cases" ind:1 deps:(3)
| Date             | Cases | Cumulative |
|------------------+-------+-------------|
| <2020-02-27 Thu> |     0 |           0 |
| <2020-02-28 Fri> |     1 |           1 |
| <2020-02-29 Sat> |     0 |           1 |
| <2020-03-01 Sun> |     0 |           1 |
| <2020-03-02 Mon> |     0 |           1 |
| <2020-03-03 Tue> |     0 |           1 |
| <2020-03-04 Wed> |     1 |           2 |
| <2020-03-05 Thu> |     1 |           3 |
| <2020-03-06 Fri> |     2 |           5 |
| <2020-03-07 Sat> |     2 |           7 |
| <2020-03-08 Sun> |     1 |           8 |
| <2020-03-09 Mon> |     0 |           8 |
| <2020-03-10 Tue> |     1 |           9 |
| <2020-03-11 Wed> |     3 |          12 |
| <2020-03-12 Thu> |     5 |          17 |
| <2020-03-13 Fri> |     6 |          23 |
| <2020-03-14 Sat> |    13 |          36 |
| <2020-03-15 Sun> |    11 |          47 |
| <2020-03-16 Mon> |     8 |          55 |
| <2020-03-17 Tue> |    22 |          77 |
| <2020-03-18 Wed> |    13 |          90 |
| <2020-03-19 Thu> |    31 |         121 |
| <2020-03-20 Fri> |    27 |         148 |
| <2020-03-21 Sat> |    33 |         181 |
| <2020-03-22 Sun> |    69 |         250 |
|------------------+-------+-------------|
  #+TBLFM: $3=vsum(@I$2..@+0$2)

[[file:coronaMeta.png]]

#+BEGIN_SRC gnuplot :var data=corona :file coronaSrcBlock.png :results graphics
set style data linespoints
set title "Corona Cases"
plot data using 1:3
#+END_SRC
| improve this answer | |
0
  • Initialize the first cell with @1$3=$2. This override the column formula which is correct.
  • use orgtbl-ascii-draw for an ascii plot
    |------------------+----+-----+--------------|
    | <2020-02-27 Thu> |  0 |   0 |              |
    | <2020-02-28 Fri> |  1 |   1 |              |
    | <2020-02-29 Sat> |  0 |   1 |              |
    | <2020-03-01 Sun> |  0 |   1 |              |
    | <2020-03-02 Mon> |  0 |   1 |              |
    | <2020-03-03 Tue> |  0 |   1 |              |
    | <2020-03-04 Wed> |  1 |   2 | .            |
    | <2020-03-05 Thu> |  1 |   3 | .            |
    | <2020-03-06 Fri> |  2 |   5 | :            |
    | <2020-03-07 Sat> |  2 |   7 | ;            |
    | <2020-03-08 Sun> |  1 |   8 | c            |
    | <2020-03-09 Mon> |  0 |   8 | c            |
    | <2020-03-10 Tue> |  1 |   9 | c            |
    | <2020-03-11 Wed> |  3 |  12 | l            |
    | <2020-03-12 Thu> |  5 |  17 | V            |
    | <2020-03-13 Fri> |  6 |  23 | W.           |
    | <2020-03-14 Sat> | 13 |  36 | Wh           |
    | <2020-03-15 Sun> | 11 |  47 | WW;          |
    | <2020-03-16 Mon> |  8 |  55 | WWl          |
    | <2020-03-17 Tue> | 22 |  77 | WWWh         |
    | <2020-03-18 Wed> | 13 |  90 | WWWW;        |
    | <2020-03-19 Thu> | 31 | 121 | WWWWWV       |
    | <2020-03-20 Fri> | 27 | 148 | WWWWWWW.     |
    | <2020-03-21 Sat> | 33 | 181 | WWWWWWWWh    |
    | <2020-03-22 Sun> | 69 | 250 | WWWWWWWWWWWW |
    |------------------+----+-----+--------------|
    #+TBLFM: $3=$2+@-1$3::@1$3=$2::$4='(orgtbl-ascii-draw $3 0 250 12)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.