1 2 // Make a plot with three groups: One for "In Meeting", one for "On Phone", 3 // and one for "Coding". The plot will also have two bar colors: One for 4 // "Without Caffeine" and one for "With Caffeine". 5 auto withoutCaffeine = [8, 6, 3]; 6 auto withCaffeine = [5, 3, 1]; 7 auto sleepinessPlot = groupedBar( 8 iota(3), [withoutCaffeine, withCaffeine], 0.6, 9 ["W/o Caffeine", "W/ Caffeine"], 10 [getColor(64, 64, 255), getColor(255, 64, 64)] 11 ); 12 auto sleepinessFig = Figure(sleepinessPlot) 13 .title("Sleepiness Survey") 14 .yLabel("Sleepiness Rating") 15 .xLabel("Activity") 16 .legendLocation(LegendLocation.right) 17 .horizontalGrid(true) 18 .xTickLabels( 19 iota(3), 20 ["In Meeting", "On Phone", "Coding"] 21 );
Create an array of bar plots that, when inserted into a Figure, will effectively become a grouped bar plot.
Parameters:
centers: An input range of the overall center of each group of bars.
data: A range of ranges, with one range for each bar color. This range should have one number for each group.
width: The combined width of all of the bars for each group.
legendText: An array of strings, one for each bar color, or null if no legend is desired.
colors: An array of colors, one for each bar. If none is provided, the default colors are used. These are, in order, blue, red, green, black, orange, and purple. If more colors are needed, they are generated using a random number generator with a deterministic seed.