3 Data Visualization - Basic Data Plotting
3.1 Data Sci Plots
Tip: Use #:x-label and #:y-label to edit the labels for those axes. For additional keywords, see the documentation for the plot function.
read
Generate a chart showing that there are 100 apples in stock and 200 bananas.
code
#lang data-sci (plot-pict #:title "Fruits in stock" (discrete-histogram '((apples 100) (bananas 200))))
3.2 Data Sci Plots
read
Generate a chart showing that there are 100 apples in stock and 200 bananas. Draw a red circle on the chart.
code
#lang data-sci (define apples-bananas (plot-pict (discrete-histogram '((apples 100) (bananas 200))))) (cc-superimpose apples-bananas (circle 200 #:border-color "red" #:border-width 10))
3.3 Data Sci Plots
read
Generate a chart showing that there are 100 apples in stock and 200 bananas. Render that chart beside itself at three different sizes.
code
#lang data-sci (define apples-bananas (plot-pict (discrete-histogram '((apples 100) (bananas 200))))) (hc-append (scale apples-bananas 2) apples-bananas (scale apples-bananas 0.5))
3.4 Data Sci Plots
read
Render two charts beside each other, at a slight rotation. One should show that there are 100 apples and 200 bananas. The other should show that there are 1000 Macs and 1000 PCs.
code
#lang data-sci (define apples-bananas (plot-pict (discrete-histogram '((apples 100) (bananas 200))))) (define macs-pcs (plot-pict (discrete-histogram #:color "green" '((macs 1000) (pcs 2000))))) (hc-append (rotate apples-bananas (/ pi 5)) (rotate macs-pcs (- (/ pi 5))))
3.5 Data Sci Plots
read
There are 1000 apples, 1500 bananas, and 3000 oranges. Render a chart that makes the point that oranges outnumber bananas and apples.
code
#lang data-sci (define data (zip '(apples bananas oranges) '(1000 1500 3000))) (plot-pict #:title "Oranges outnumber bananas and apples" (discrete-histogram data))
3.6 Data Sci Plots
read
There are 1000 apples, 1500 bananas, and 3000 oranges. Render a chart with a large y-axis, making the point that all fruits are scarse.
code
#lang data-sci (define data (zip '(apples bananas oranges) '(1000 1500 3000))) (plot-pict #:title "All fruits scarse" #:y-max 10000 (discrete-histogram data))
3.7 Data Sci Plots
read
There are two machines, the "Magic Cooker" and the "Cook 2000". Each can cook Eggs, Bacon, and Pancakes in under 4 minutes. Make up data for each one and plot the data on a bar chart that compares their cooking times.
code
#lang data-sci (define magic-cooker-data '((Eggs 1.5) (Bacon 2.5) (Pancakes 3.5))) (define cook-2000-data '((Eggs 1.4) (Bacon 2.3) (Pancakes 3.1))) (plot #:x-label "Breakfast Food" #:y-label "Cooking Time (minutes)" #:title "Cooking Times For Breakfast Food, Per Processor" (list (discrete-histogram magic-cooker-data #:skip 2.5 #:x-min 0 #:label "The Magic Cooker") (discrete-histogram cook-2000-data #:skip 2.5 #:x-min 1 #:label "The Cook 2000" #:color 2 #:line-color 2)))