Racket: Plot interleaved discrete-histograms

DrRacket is great for checking code developed with Emacs geiser-mode. After pasting the text from and Emacs buffer and clicking the “Run” button, DrRacket reminds me of all the definitions from previous scripts and REPL experiments that never made it into the file.

DrRacket Code and Plots for Interleaved Discrete-Histograms

This code is still clumsy, the process isn't clear enough in my mind for elegant solutions. But working through the process is great for learning. This may be a way to re-discover the faceting that R/ggplot2 makes possible. I think this is the best way to get a feel for how an individual teachers results are situated in relation to the groups: the individual's department and school.

It would be great to get Racket-competent students and citizens with questions to explore. We could implement the Questionnaires and their Visualization ourselves, with good questions it might be possible to continue the work of Ignacio Martin-Baro and Ignacio Ellacuria “Towards a Society that Serves its People”. In the meantime these Faculty Development Questionnaires provide data for training in computer languages, data transformations, and information designs.

Interleaved Discrete Histogram: enthused facet

Although DrRacket is great, Emacs keybindings for going to the start and end of lines, for switching buffers and windows, for going to the head or tail of a buffer, and the keyboard macros just make development smoother.

Racket code development in Emacs with Geiser

It's always a shock to press [Ctrl]-[e] and have a DrRacket panel disappear. But DrRacket is fun, the arrows that show you where definitions come from....

code

#lang racket

 (current-directory "FD201801")
 (current-directory-for-user "FD201801")

;;(require racket/format) ;; for ~r #:precision
;;(require plot/utils) ;; linear-seq exact->inexact
(require plot) ;; discrete-histogram, stacked-histogram etc
;; (require scribble/html/html) ;; to view png files in browser
;; (require scribble/html) ;; output-xml to make .html page for browser

;; (define RsEng (map (lambda (l) (list (car l) (cadddr l))) responses))
;; (define QsEng (map cadr questions-English))

(define quest-symbs '(出席 発言 取組 聞取 資料 時刻 反応 熱意 理解 役立 満足))

(define ind-als ;;教員の連帯リスト associative list
  '((nme (教員 TCR スモール 教養))
    (smr (2018 1 H30 Z)) ;; 学期 SeMesteR
    (cls (1 84))         ;; 授業、教室 CLasS
    (dta ((62 13 9 0 0)   ;; データ、DaTA
	 (19 24 28 6 6)
	 (23 24 27 6 4)
	 (53 22 9 0 0)
	 (35 29 19 0 1)
	 (64 12 7 1 0)
	 (54 19 10 1 0)
	 (69 9 6 0 0)
	 (34 28 16 4 1)
	 (43 25 12 2 1)
	 (35 25 20 2 1)))))

(define dep-als ;;学科 associative list
  '((nme (学科 DPT 教養 大学))
    (smr (2018 1 H30 Z))
    (cls (7 269))
    (dta ((202 41 26 0 0)
    (62 68 99 22 17)
    (72 74 98 14 11)
    (144 67 41 9 8)
    (111 78 55 13 10)
    (171 60 28 5 4)
    (140 65 46 10 8)
    (165 62 27 9 6)
    (96 98 51 14 8)
    (119 76 56 8 8)
    (109 79 60 9 10)))))

(define uni-als ;;大学
  '((nme (大学 UVY 南九州 学園))
    (smr (2018 1 H30 Z))
    (cls (59 2452))
    (dta ((1738 472 206 23 8)
     (495 549 923 195 283)
     (713 765 736 162 65)
     (1400 628 296 86 35)
     (1264 630 384 110 55)
     (1795 446 166 25 13)
     (1378 654 317 59 38)
     (1573 588 230 33 20)
     (976 886 438 99 42)
     (1411 684 289 33 24)
     (1217 740 388 58 38)))))

(define als-ref
  (lambda (idx als)
    (let ((tmp (assv idx als)))
      (if tmp (cadr tmp) #f))))

(define count->percent
  (lambda (lst) ;; list of lists
    (let ((total (apply + lst)))
      (map (lambda (cnt)
	     (* (/ cnt total) 100.0))
	   lst))))
;; might need to truncate decimal places for labels later
;; in plot/utils  (real->decimal-string num 2) (r->d-s num min)
(define vctrz-rspns-prcnt
  (lambda (lst)
    (map vector '(5 4 3 2 1) (count->percent lst))))
(define labl-from-alst
  (lambda (als)
    (format "~a~a" (car (als-ref 'nme als)) (cadr (als-ref 'nme als)))))

(define intrleav-3-dsct-hstm-1
  (lambda (l1 l2 l3)
    (list
     (discrete-histogram
      l1
      #:skip 3.5 #:x-min 0
      #:label "教員TCR") ;; 教員
     (discrete-histogram
      l2
      #:skip 3.5 #:x-min 1  ;; 学科
      #:label "学科DEP" #:color 2 #:line-color 2)
     (discrete-histogram
      l3
      #:skip 3.5 #:x-min 2  ;; 大学
      #:label "大学UVY" #:color 4 #:line-color 4))))

(map (lambda (l1 l2 l3 Q)
       (plot (intrleav-3-dsct-hstm-1
	      (vctrz-rspns-prcnt l1)
	      (vctrz-rspns-prcnt l2)
	      (vctrz-rspns-prcnt l3))
	     #:title (symbol->string Q) #:x-label "Response Level"
             #:y-label "Percent" #:y-max 100
             #:legend-anchor 'top-right
             #:height 300))
     (als-ref 'dta ind-als)
     (als-ref 'dta dep-als)
     (als-ref 'dta uni-als)
     quest-symbs)
;; need a function that will take alists and plot to file

(define plot-3-alsts-intrleaved-to-file
  (lambda (als1 als2 als3 Qsymbs)
    (map (lambda (l1 l2 l3 Q)
	   (plot-file (intrleav-3-dsct-hstm-1
		       (vctrz-rspns-prcnt l1)
		       (vctrz-rspns-prcnt l2)
		       (vctrz-rspns-prcnt l3))
		      #:title (symbol->string Q)
		      #:x-label "Response Value"
		      #:y-label "Percent%"
		      #:y-max 100
		      #:legend-anchor 'top-right
                      #:height 300
		      (format "~a~a~a~a.png" (symbol->string Q)
			       (car (als-ref 'smr als1))
			       0
			       (cadr (als-ref 'smr als1)))
		      'png))
	 (als-ref 'dta als1)
	 (als-ref 'dta als2)
	 (als-ref 'dta als3)
	 Qsymbs)))

(plot-3-alsts-intrleaved-to-file ind-als dep-als uni-als quest-symbs)

#Scheme #Racket #FS4FT #FS4FD #facdev #FacultyDevelopment #DataVisualizatoin #アンケート #データ視覚化