help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Plotting in Emacs?


From: Jean Louis
Subject: Re: Plotting in Emacs?
Date: Tue, 18 Apr 2023 07:38:53 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Marcin Borkowski <mbork@mbork.pl> [2023-04-18 07:18]:
> we all know Emacs can draw -- there's Artist mode, there are SVGs and
> XBMs etc.  Do you know of any packages which could use these features to
> plot charts directly in an Emacs buffer?  Bonus points of the input can
> be an Org mode table (or a fragment of it, say the last 180 rows).  They
> can be ASCII art charts or SVGs, or even XBMs -- I don't care.  I would
> prefer, though, not to call gnuplot or other external software -- doing
> it all in Elisp would be better.  (Though gnuplot would be ok if I could
> show the plot in the Org buffer, which is probably possible -- still,
> I'd like to explore my alternatives.)

This is not a package, just a guidance for you to use chart.el Emacs
library.

In this function I am getting some basic data I need, how you will get
data from Org table is for you to figure it out.

(defun cf-interactions-chart (&optional id)
  "Opens up new chart buffer for interactions for contact ID"
  (interactive)
  (when-tabulated-id "people"
      (let* ((sql (format "SELECT interactiontypes_name, interactions_count 
FROM interactiontypes, interactions WHERE interactions_people = %s AND 
interactions_interactiontypes = interactiontypes_id" id))
             (data (rcd-sql-list sql cf-db))
             (title (concat "Interactions with " (cf-people-name id)))
             (namelst (reverse (mapcar (lambda (i) (car i)) data)))
             (nametitle "Types of interactions")
             (numlst (reverse (mapcar (lambda (i) (cadr i)) data)))
             (numtitle "Number of interactions"))
        (chart-bar-quickie 'vertical title namelst nametitle numlst numtitle))))

The result of that function is shown on this picture:
https://gnu.support/images/2023/04/2023-04-18/Screenshot-2023-04-18-07-29-53-903005389.png

> I found `orgtbl-ascii-plot', which looks great, but not exactly what
> I want -- it gives a "vertical" plot going down, and I want a more
> traditional "horizontal" plot going right.

I cannot know what you mean with horizontal plot.

Another function I use to create statistics uses R:

(defun rcd-r-pie-chart (title labels values output-file &optional overwrite 
colors)
  (let* ((values (mapcar #'number-to-string values))
         (colors (or colors (rcd-r-colors (length values))))
         (colors (mapcar #'string-to-single-quotes colors))
         (colors (string-join colors ", "))
         (values (string-join values ", "))
         (labels (mapcar #'string-to-single-quotes labels))
         (labels (string-join labels ", "))
         (script (format "
# Draw Pie Chart in R
 
# Data for Pie chart
x = c(%s)
labels = c(%s)

colors = c(%s)
 
# Give the chart file a name.
png(file = \"%s\", width=800, height=800)
 
# Plot the chart.
pie(x, labels=labels, height=0.20, main='%s', col=colors)
 
# Save the file.
dev.off()
" values labels colors output-file title)))
    (if (and (file-exists-p output-file) (not overwrite))
        (if (yes-or-no-p (format "Delete %s?" output-file))
            (delete-file output-file)))
    (string-to-file-force script "~/script")
    (rcd-command-output-from-input "R" script "--vanilla")
    (if (not (file-exists-p output-file))
        (rcd-warning-message "File %s not created. Verify why." output-file)
      (find-file output-file))))

And the result of that function is shown here:
https://gnu.support/images/2023/04/2023-04-18/stat.jpg

For those few missing functions you need to make the above work, you
can contact me privately.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]