ghollisjr / cl-ana

Free (GPL) Common Lisp data analysis library with emphasis on modularity and conceptual clarity.
GNU General Public License v3.0
196 stars 18 forks source link

xticslabels option for boxes #9

Closed hendersonmpa closed 8 years ago

hendersonmpa commented 8 years ago

More of a question than an issue. I would like to create categorical barcharts using the cl-ana gnuplot interface. I have tried a few approaches to get xticlabels to work in the :line-args slots (see below). I wanted to check if I there is a way to do this prior to trying to find my way towards to adding this option.

I would like to replicate this gnuplot code

plot 'barplot.dat' using 2:xticlabels(1) with boxes

with cl-ana.plotting:draw

(cl-ana.plotting:draw  '(("blue" . 3)
                        ("red" . 2)
                        ("green" . 1))
                       :line-args '(:style "boxes"
                                    :line-options "2:xticlabels(1)")
                      :plot-args '(:x-range (0 . 4)
                                   :y-range (0 . 4))
                      :page-args (list :terminal (cl-ana.plotting:wxt-term :size (cons 800 600))))

Thanks for a great package

ghollisjr commented 8 years ago

Hi hendersonmpa,

Sorry for the delayed response, this is one of the things that still needs to be documented, but the way you would create a categorical barchart would be to use the cl-ana.plotting:tics function to create custom tic labels. You will need to index your actual data however you wish, and then assign custom tic labels, so for your example (assuming you're in the cl-ana package):

(draw '((1 . 3)
        (2 . 2)
        (3 . 1))
      :line-args '(:style "boxes")
      :plot-args (list :x-range '(0 . 4)
                       :y-range '(0 . 4)
                       :x-tics (tics :manual-labels
                                     (list (list :name "blue"
                                                 :position 1)
                                           (list :name "red"
                                                 :position 2)
                                           (list :name "green"
                                                 :position 3)))))

The documentation for the cl-ana.plotting:tics function contains more detailed information on how to use it along with the merge-tics function.