-
Notifications
You must be signed in to change notification settings - Fork 9
/
brewscheme.ado
1550 lines (1107 loc) · 53.8 KB
/
brewscheme.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
********************************************************************************
* Description of the Program - *
* This program is a tool to facilitate Stata users developing graph schemes *
* using research-based color palettes. Unlike other uses of the color *
* palettes developed by Brewer (see References below), this program allows *
* users to specify the number of colors from any of the 35 color palettes they *
* would like to use and allows users to mix/combine different palettes for the *
* various graph types. *
* *
* Data Requirements - *
* none *
* *
* System Requirements - *
* none *
* *
* Program Output - *
* scheme-`schemename'.scheme *
* *
* Lines - *
* 1548 *
* *
********************************************************************************
*! brewscheme
*! v 1.0.2
*! 09NOV2016
// Drop the program from memory if loaded
cap prog drop brewscheme
// Define the program as an rclass program
prog def brewscheme, rclass
// Specify the version number
version 13.1
// Define the syntax structure of the program
syntax , SCHEMEname(string asis) ///
[ ALLSTyle(string asis) ALLColors(real 3) ALLSATuration(real 100) ///
BARSTyle(string asis) BARColors(real 3) BARSATuration(real 100) ///
SCATSTyle(string asis) SCATColors(real 3) SCATSATuration(real 100) ///
AREASTyle(string asis) AREAColors(real 3) AREASATuration(real 100) ///
LINESTyle(string asis) LINEColors(real 3) LINESATuration(real 100) ///
BOXSTyle(string asis) BOXColors(real 3) BOXSATuration(real 100) ///
DOTSTyle(string asis) DOTColors(real 3) DOTSATuration(real 100) ///
PIESTyle(string asis) PIEColors(real 3) PIESATuration(real 100) ///
SUNSTyle(string asis) SUNColors(real 4) SUNSATuration(real 100) ///
HISTSTyle(string asis) HISTColors(real 3) HISTSATuration(real 100) ///
CISTyle(string asis) CIColors(real 3) CISATuration(real 100) ///
MATSTyle(string asis) MATColors(real 3) MATSATuration(real 100) ///
REFLSTyle(string asis) REFLColors(real 3) REFLSATuration(real 100) ///
REFMSTyle(string asis) REFMColors(real 3) REFMSATuration(real 100) ///
CONSTart(string asis) CONEnd(string asis) CONSATuration(real 100) ///
SOMESTyle(string asis) SOMEColors(real 3) SOMESATuration(real 100) ///
REPlace DBug THEMEFile(string asis) SYMBols(string asis) ]
// Check for brewscheme Mata library
qui: brewlibcheck
// Define local with valid symbols arguments
loc validsymbols circle diamond triangle square plus smcircle ///
smdiamond smsquare smtriangle smplus smx circle_hollow ///
diamond_hollow triangle_hollow square_hollow smcircle_hollow ///
smdiamond_hollow smtriangle_hollow smsquare_hollow point none
// Check for symbols argument
if `"`symbols'"' != "" {
// Get the number of symbols passed
loc numsymbols `: word count `symbols''
// Loop over symbols
forv i = 1/`numsymbols' {
// Get the individual symbol argument
loc thissymbol `: word `i' of `symbols''
// Check if valid symbol
if `: list thissymbol in validsymbols' == 0 {
// Display error message in the console
di as err `"The argument `thissymbol' passed to the "' ///
"symbols parameter is invalid. Must be one of "' ///
`"`: subinstr loc validsymbols `" "' `", "', all'."'
// Issue generic error code
err 198
} // End IF Block for argument validation
} // End Loop over symbols arguments for validation
} // End IF Block to validate symbol arugments
// If no argument passed default to circle
else {
// Set number of symbols local
loc numsymbols = 1
// Set symbols to default to circle
loc symbols circle
} // End ELSE Block for null symbols parameter
// Preserve data currently loaded in memory
preserve
// Check for directory and if not build it
dirfile `c(sysdir_personal)', p(b)
// Check for subdirectory used for storing scheme files
dirfile `c(sysdir_plus)', p(s)
// Check for the metadata dataset
cap confirm new file `"`c(sysdir_personal)'b/brewmeta.dta"'
// If file doesn't exist
if inlist(_rc, 0, 603) {
// Call brewmeta to build lookup data set
qui: brewdb, `replace'
// Load the lookup table
qui: use `"`c(sysdir_personal)'b/brewmeta.dta"', clear
} // End IF Block to build look up data set
// Check for file
cap confirm new file `"`c(sysdir_personal)'b/brewmeta.dta"'
// If file doesn't exist
if inlist(_rc, 0, 603) | "`replace'" != "" {
// Call brewmeta to build lookup data set
qui: brewdb, `replace'
// Load the lookup table
qui: use `"`c(sysdir_personal)'b/brewmeta.dta"', clear
} // End IF Block to build look up data set
// If the file exists load it
else {
// Load the lookup table
qui: use `"`c(sysdir_personal)'b/brewmeta.dta"', clear
} // End ELSE Block to load brewmeta file
// Get acceptable palette names
qui: levelsof palette, loc(palettes)
// Initialize a new brewcolors class
qui: mata: brewc = brewcolors()
// Loop over the palette names
foreach v of loc palettes {
// Get the maximum number of colors available in the palette
qui: su maxcolors if palette == `"`v'"', meanonly
// Store in the macro with the name of the palette followed by c
loc `v'c = `r(mean)'
} // End Loop to get maximum number of colors per palette
// Set local with the graph type stub names
loc gr1 bar scat area line con box dot pie
loc gr2 sun hist ci mat refl refm
loc grstyles `gr1' `gr2'
/* Validate arguments (if all graph types are null, an all parameter
must be specified */
if mi("`barstyle'") & mi("`scatstyle'") & mi("`areastyle'") & ///
mi("`linestyle'") & mi("`constart'") & mi("`boxstyle'") & ///
mi("`dotstyle'") & mi("`piestyle'") & mi("`sunstyle'") & ///
mi("`histstyle'") & mi("`cistyle'") & mi("`matstyle'") & ///
mi("`reflstyle'") & mi("`refmstyle'") & mi("`allstyle'") & ///
mi("`conend'") {
// Print error message to the screen
di as err "Must include either arguments for the all " ///
"parameters or use a combination of graph type arguments and " ///
"some arguments to provide default colors to the other graph types"
// Kill the program
exit
} // End IF Block for valid arguments
// If all the graph styles are missing and an all style is specified
else if mi("`barstyle'") & mi("`scatstyle'") & mi("`areastyle'") & ///
mi("`linestyle'") & mi("`boxstyle'") & mi("`dotstyle'") & ///
mi("`piestyle'") & mi("`sunstyle'") & mi("`histstyle'") & ///
mi("`cistyle'") & mi("`matstyle'") & mi("`reflstyle'") & ///
mi("`refmstyle'") & mi("`constart'") & mi("`conend'") & ///
!mi("`allstyle'") {
// Checks the saturation values and returns valid value if
// invalid argument is passed
checkSat, int(`allsaturation')
// Resets the local to the corrected value
loc allsaturation = `r(saturation)'
// Set the style parameters for all graph types to the values in the
// all parameters
if `allcolors' <= ``allstyle'c' {
// Check to see if all style was an available palette
if `: list allstyle in palettes' != 1 {
// Let user know valid values
di as err `"Styles arguments must be one of: `palettes'"'
// Exit program
exit
} // End IF Block to check for valid color palette
// Loop over graph types and assign the all styles to them
foreach stile in "bar" "scat" "area" "line" "box" ///
"dot" "pie" "sun" "hist" "ci" "mat" "refl" "refm" {
/* Assign the all style, color, and saturation levels to the
individual graph types. */
loc `stile'style `allstyle'
loc `stile'colors `allcolors'
loc `stile'saturation `allsaturation'
} // End Loop over graph types
// Sets the palette for the starting color for contourplots
loc constart `allstyle'
// Sets the palette for the ending color for contourplots
loc conend `allstyle'
} // End IF Block to check if the # of colors is valid for the style
// If the user selected more colors than available in the palette
else {
// Print error message to the screen
di as err `"More colors (`allcolors') than "' ///
`"available (``allstyle'c') in the palette `allstyle'"'
// Kill the program
exit
} // End ELSE Block for # colors > available colors
} // End ELSEIF Block for missing graph styles with nonmissing all style
// If missing some arguments make sure some parameters have values
else if ("`barstyle'" == "" | "`scatstyle'" == "" | ///
"`areastyle'" == "" | "`linestyle'" == "" | ///
"`boxstyle'" == "" | "`dotstyle'" == "" | ///
"`piestyle'" == "" | "`sunstyle'" == "" | ///
"`histstyle'" == "" | "`cistyle'" == "" | ///
"`matstyle'" == "" | "`reflstyle'" == "" | ///
"`refmstyle'" == "" | "`constart'" == "" | "`conend'" == "") & ///
"`somestyle'" == "" {
// If missing some graph type styles must include defaults in some
di as err "Must include arguments for somestyle if missing graph types"
// Kill program
exit
} // End ELSEIF Block for missing types w/o some argument
// If missing some graph types and defaults provided
else if ("`barstyle'" == "" | "`scatstyle'" == "" | ///
"`areastyle'" == "" | "`linestyle'" == "" | ///
"`boxstyle'" == "" | "`dotstyle'" == "" | ///
"`piestyle'" == "" | "`sunstyle'" == "" | ///
"`histstyle'" == "" | "`cistyle'" == "" | ///
"`matstyle'" == "" | "`reflstyle'" == "" | ///
"`refmstyle'" == "" | "`constart'" == "" | "`conend'" == "") & ///
"`somestyle'" != "" {
// Check to see if some style was an available palette
if `: list somestyle in palettes' != 1 {
// Let user know valid values
di as err "Styles arguments must be one of: " _n `"`palettes'"'
// Exit program
exit
} // End IF Block to check for valid color palette
// Tests the saturation value for the some option
checkSat, int(`somesaturation')
// Returns the corrected values to the same local
loc somesaturation = `r(saturation)'
// If more colors specified for default than available
if `somecolors' > ``somestyle'c' & `somecolors' != . {
// Print error message to screen
di as err `"More colors (``stile'colors') than "' ///
`"available (``stile'style') in the palette "' ///
`""`stile'style" = ``somestyle'c'"'
// Kill the program
err 198
} // End ELSEIF Block for # colors > available for defaults
// Loop over # available colors per graph
foreach stile in `grstyles' {
// Check contour plot scheme arguments
if `"``stile'start'"' == "" loc constart "`somestyle'"
if `"``stile'end'"' == "" loc conend "`somestyle'"
// If the style is missing and valid # colors for default
if "``stile'style'" == "" {
// Assign the default styles to the graph type
loc `stile'style "`somestyle'"
loc `stile'colors `somecolors'
loc `stile'saturation `somesaturation'
} // End IF Block for unspecified graphs
// If the graph type has a style specified
else {
// Check to see if there are the requested number of colors
if ``stile'colors' > ```stile'style'c' {
// If not print error to screen
di as err `"Too many colors specified in "' ///
`"`stile'colors(``stile'colors') for the "' ///
`"``stile'style' palette."' _n ///
`"Maximum number of colors allowed is ```stile'style'c'"'
// Issue error code and exit
err 198
} // End IF Block for more colors than available
// If there are an appropriate number of colors requested
else {
// Check the saturation values
checkSat, int(``stile'saturation')
// And replace the passed argument with the validated value
loc `stile'saturation = `r(saturation)'
} // End ELSE Block for sufficient colors
} // End ELSE Block for graphs with specified color palettes
} // End Loop over graph types
} // End ELSEIF Block for valid parameters
// For cases where all styles are specified
else {
// Loop over # available colors per graph
foreach stile in `grstyles' {
// Skip over contour plot case
if `"`stile'"' == "con" continue
// Check to see if there are the requested number of colors
else if ``stile'colors' > ```stile'style'c' {
// If not print error to screen
di as err `"Too many colors specified in "' ///
`"`stile'colors(``stile'colors') for the "' ///
`"``stile'style' palette."' _n ///
`"Maximum number of colors allowed is ```stile'style'c'"'
// Issue error code and exit
err 198
} // End ELSEIF Block for more colors than available
// If there are an appropriate number of colors requested
else {
// Check the saturation values
checkSat, int(``stile'saturation')
// And replace the passed argument with the validated value
loc `stile'saturation = `r(saturation)'
} // End ELSE Block for sufficient colors
} // End Loop over graph types
} // End ELSE Block for cases with all graph types specified
// Line saturation gets defined as a color multiplier
// loc linesaturation = `linesaturation'/100
// Dot plot saturation is defined as a color multiplier
// loc dotsaturation = `dotsaturation'/100
// Scatterplot saturation gets defined as a color multiplier
// loc scatsaturation = `scatsaturation'/100
// Use a tempname for the scheme file filehandle
tempname scheme1 scheme2 scheme3 scheme4 scheme5
// Root file path to theme files
loc themeroot `"`c(sysdir_personal)'b/theme/theme"'
// Root file path for brewscheme created scheme files
loc schemeroot `"`c(sysdir_plus)'/s/scheme"'
// Write the scheme file to a location on the path
qui: file open `scheme1' using `"`schemeroot'-`schemename'.scheme"', w replace
qui: file open `scheme2' using ///
`"`schemeroot'-`schemename'_achromatopsia.scheme"', w replace
qui: file open `scheme3' using ///
`"`schemeroot'-`schemename'_protanopia.scheme"', w replace
qui: file open `scheme4' using ///
`"`schemeroot'-`schemename'_deuteranopia.scheme"', w replace
qui: file open `scheme5' using ///
`"`schemeroot'-`schemename'_tritanopia.scheme"', w replace
// Find maximum number of colors to set the recycle parameter
loc pcycles = max( `barcolors', `scatcolors', `areacolors', ///
`linecolors', `boxcolors', `dotcolors', ///
`piecolors', `suncolors', `histcolors', ///
`cicolors', `matcolors', `reflcolors', ///
`refmcolors')
// Recycle the number of symbols
qui: mata: recycle(`numsymbols', `pcycles')
// Loop over the sequence of symbols
foreach symb in `sequence' {
// Build a string with each of the symbols corresponding to the
// appropriate cycle number
loc symbolseq `"`symbolseq' "`: word `symb' of `symbols''""'
} // End Loop over symbol sequence
// Check to see if start and end contour color palettes are the same
if `"`constart'"' == `"`conend'"' {
// Get version of palette w/minimum number of colors
qui: su pcolor if palette == `"`constart'"'
// Get the RGB values for the given palette and number of colors
mata: brewc.getPalette(`"`constart'"', `r(min)')
// Overwrite the local macro with the RGB value
loc constart `: word 1 of `rgbs''
// Overwrite the local macro with the RGB value
loc conend `: word 2 of `rgbs''
} // End IF Block for case where contour start/end use same palette
// If they use different palettes
else {
// Get version of palette with minimum number of colors for start
qui: su pcolor if palette == `"`constart'"'
// Get the RGB values for the given palette and number of colors
mata: brewc.getPalette(`"`constart'"', `r(min)')
// Overwrite the local macro with the RGB value
loc constart `: word 1 of `rgbs''
// Get version of palette with minimum number of colors for start
qui: su pcolor if palette == `"`conend'"'
// Get the RGB values for the ending color for contour plots for
// the given color palette
mata: brewc.getPalette(`"`conend'"', `r(min)')
// Overwrite the local macro with the RGB value second word used here
// to prevent same color issue if the allstyle option is used.
loc conend `: word 2 of `rgbs''
} // End ELSE Block for separate start/end contour palettes
// Loop over color macros
foreach color in bar scat area line box dot pie hist ci mat ///
refl refm sun {
/* Create the sequence of color ids for each graph type based on
the maximum number of colors in any listed color argument. */
qui: mata: recycle(``color'colors', `pcycles')
// Assign the id sequence to a local with seq as suffix
loc `color'seq = `"`sequence'"'
// Get the colors for the specified palette and number of colors
mata: brewc.getPalette("``color'style'", ``color'colors')
// Developer option to print debug messages
if "`dbug'" != "" {
// Prints the graph type with data that follows
di "Graph type = `color'"
// Print debugging message
di "Color: `color'" _n "Number of colors: ``color''" _n ///
`"Color sequence: ``color'seq'"'
} // End Debug messages
// Loop over the rgb values to construct the graph specific
// rgb values
foreach c of loc `color'seq {
// Construct macro with RGB values for lookup
loc `color'rgb `"``color'rgb' "`: word `c' of `rgbs''" "'
} // End Loop
// Create marker for graph type with maximum number of colors
if ``color'colors' == `pcycles' {
// Set the generic color macro to reference macro w/max colors
loc gencolor `"``color'rgb'"'
} // End of IF Block to define generic color macro
// Check for debug option
if "`dbug'" != "" {
// Print the RGB color string to screen
di `"``color'rgb'"'
} // End debug option
} // End Loop over number of colors for graph types
// Stubs to use for line references to theme files
loc linerefs theme1 theme2 theme3 theme4 theme5
// Tempnames
tempname theme1 theme2 theme3 theme4 theme5
// Check for theme file
if `"`themefile'"' != "" {
// Themefile names
loc themerefs `"`themeroot'-`themefile'.theme"' ///
`"`themeroot'-`themefile'_achromatopsia.theme"' ///
`"`themeroot'-`themefile'_protanopia.theme"' ///
`"`themeroot'-`themefile'_deuteranopia.theme"' ///
`"`themeroot'-`themefile'_tritanopia.theme"'
// Loop over theme files
forv thf = 1/5 {
// Open the first file
file open `theme`thf'' using `"`: word `thf' of `"`themerefs'"''"', r
// zero value local macro
loc x = 1
// Read the first line of the file
file read `theme`thf'' theme`thf'_`x'
// Loop until end of file
while r(eof) == 0 {
// Increment line counter
loc x = `x' + 1
// Read line into local macro
file read `theme`thf'' theme`thf'_`x'
} // End Loop over theme file
// Close the file connection
file close `theme`thf''
} // End Loop over themefiles
} // End IF Block for user specified theme file
// If user does not specify a file
else {
// Check for default file
cap confirm file `"`themeroot'-default.theme"'
// If the default file exists
if _rc != 0 {
// Create the default brewtheme files
qui: brewtheme
} // End IF Block to open a connection to the default theme
// Themefile names
loc themerefs `"`themeroot'-default.theme"' ///
`"`themeroot'-default_achromatopsia.theme"' ///
`"`themeroot'-default_protanopia.theme"' ///
`"`themeroot'-default_deuteranopia.theme"' ///
`"`themeroot'-default_tritanopia.theme"'
// Loop over theme files
forv thf = 1/5 {
// Open the first file
file open `theme`thf'' using `"`: word `thf' of `"`themerefs'"''"', r
// zero value local macro
loc x = 1
// Read the first line of the file
file read `theme`thf'' theme`thf'_`x'
// Loop until end of file
while r(eof) == 0 {
// Increment line counter
loc x = `x' + 1
// Read line into local macro
file read `theme`thf'' theme`thf'_`x'
} // End Loop over theme file
// Close the file connection
file close `theme`thf''
} // End Loop over themefiles
} // End ELSE Block for null theme file
// Name extension macros
loc nameext "" "_achromatopsia" "_protanopia" "_deuteranopia" "_tritanopia"
// Loop over the theme/scheme file pairs
forv j = 1/5 {
// Correction for schemenames
if `j' == 1 loc schemelabel `"label "`schemename'""'
// For all other cases
else loc schemelabel `"label "`schemename'`: word `j' of `nameext''""'
file write `scheme`j'' `"* s2color.scheme"' _n
file write `scheme`j'' `""' _n
file write `scheme`j'' `"* s2 scheme family with a naturally white background (white plotregions and"' _n
file write `scheme`j'' `"* lightly colored background) and color foreground (lines, symbols, text, etc)."' _n
file write `scheme`j'' `""' _n
file write `scheme`j'' `"* For p[#][stub] scheme references the corresponding style is resolved by"' _n
file write `scheme`j'' `"* searching the scheme ids with the following preference ordering:"' _n
file write `scheme`j'' `"*"' _n
file write `scheme`j'' `"* p#stub"' _n
file write `scheme`j'' `"* pstub"' _n
file write `scheme`j'' `"* p#"' _n
file write `scheme`j'' `"* p"' _n
file write `scheme`j'' `"*"' _n
file write `scheme`j'' `"* Thus it is possible to control the selected style to great detail, or let it"' _n
file write `scheme`j'' `"* default to common defaults. In particular -p- or -pstub- without"' _n
file write `scheme`j'' `"* # can be used to designate a common plotting symbol, or back plotting"' _n
file write `scheme`j'' `"* symbol, or for that matter common color or sizes."' _n
file write `scheme`j'' `"*"' _n
file write `scheme`j'' `"* "style"s designated "special" are not styles at all, but direct signals to"' _n
file write `scheme`j'' `"* graphs, plots, or other classes and their parsers. Their contents are"' _n
file write `scheme`j'' `"* specific to the use and may only be understood by the caller."' _n
file write `scheme`j'' `""' _n
file write `scheme`j'' `"*! version 1.2.5 16jun2011"' _n(2)
file write `scheme`j'' `"sequence 1299"' _n
file write `scheme`j'' `"`schemelabel'"' _n(2)
file write `scheme`j'' `"system naturally_white 1"' _n(3)
// Loop over first 10 lines of theme file
forv i = 1/10 {
// Write each line to the scheme file
file write `scheme`j'' `theme`j'_`i''
} // End Loop over lines 1-10 of theme file
file write `scheme`j'' `"numstyle pcycle `pcycles'"' _n(2)
// Loop over lines 11-16 of the theme file
forv i = 11/16 {
// Write each line to the scheme file
file write `scheme`j'' `theme`j'_`i''
} // End loop over lines 11-16 of the theme file
file write `scheme`j'' `"numstyle contours `pcycles'"' _n(2)
// Loop over lines 17-179 of the theme file
forv i = 17/179 {
// Write each line to the scheme file
file write `scheme`j'' `theme`j'_`i''
} // End loop over lines 17-179 of the theme file
} // End Loop over scheme/theme file pairs
// Local with color type refs
loc ctyperefs rgb achromatopsia protanopia deuteranopia tritanopia
// Get the area1 rgb values
mata: brewc.brewColorSearch("`: word 1 of `areargb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc ci_area`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Get the cysymbol rgb values
mata: brewc.brewColorSearch("`: word 1 of `cirgb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc ci_symbol`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Get the area1 rgb values
mata: brewc.brewColorSearch("`: word 2 of `areargb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc ci2_area`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Get the cysymbol rgb values
mata: brewc.brewColorSearch("`: word 2 of `cirgb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc ci2_symbol`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Search for histogram color
mata: brewc.brewColorSearch("`: word 1 of `histrgb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc histogram`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Search for generic sunflower plot color
mata: brewc.brewColorSearch("`: word 1 of `sunrgb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc sunflower`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Search for generic light flower
mata: brewc.brewColorSearch("`: word 2 of `sunrgb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc sunflowerlf`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Search for generic dark flower
mata: brewc.brewColorSearch("`: word 3 of `sunrgb''")
// Loop over macros
forv rfs = 1/5 {
// Store all the translated RGB values
loc sunflowerdf`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over macro reassignments
// Search for contour start values
mata: brewc.brewColorSearch("`constart'")
// Store the contour start values
forv rfs = 1/5 {
// Index values like other graph types
loc constart`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over contour plot starting values
// Search for contour end values
mata: brewc.brewColorSearch("`conend'")
// Store the contour end values
forv rfs = 1/5 {
// Index values like other graph types
loc conend`rfs' ``: word `rfs' of `ctyperefs'''
} // End Loop over contour plot ending values
// Loop over scheme/theme file pairs
forv j = 1/5 {
file write `scheme`j'' `"color ci_line "0 0 0""' _n
file write `scheme`j'' `"color ci_arealine "0 0 0""' _n
file write `scheme`j'' `"color ci_area "`ci_area`j''" "' _n
file write `scheme`j'' `"color ci_symbol "`ci_symbol`j''" "' _n
file write `scheme`j'' `"color ci2_line "0 0 0""' _n
file write `scheme`j'' `"color ci2_arealine "0 0 0""' _n
file write `scheme`j'' `"color ci2_area "`ci2_area`j''" "' _n
file write `scheme`j'' `"color ci2_symbol "`ci2_symbol`j''" "' _n(2)
file write `scheme`j'' `"color pieline "0 0 0""' _n(2)
// Writes line 180 from the theme file
file write `scheme`j'' `theme`j'_180'
// Writes line 181 from the theme file
file write `scheme`j'' `theme`j'_181'
file write `scheme`j'' `"color refmarker "0 0 0""' _n
file write `scheme`j'' `"color refmarkline "0 0 0""' _n
file write `scheme`j'' `"color histogram "`histogram`j''" "' _n
// Writes line 182 from the theme file
file write `scheme`j'' `theme`j'_182'
file write `scheme`j'' `"color histogram_line "0 0 0""' _n
file write `scheme`j'' `"color dot_line "0 0 0""' _n
file write `scheme`j'' `"color dot_arealine "0 0 0""' _n
file write `scheme`j'' `"color dot_area "`ci_area`j''" "' _n
file write `scheme`j'' `"color dotmarkline "0 0 0""' _n(2)
file write `scheme`j'' `"color xyline "0 0 0""' _n
file write `scheme`j'' `"color refline "0 0 0""' _n
file write `scheme`j'' `"color dots "0 0 0""' _n(2)
// Loop over lines 183-192 of the theme file
forv i = 183/192 {
// Write each line to the scheme file
file write `scheme`j'' `theme`j'_`i''
} // End loop over lines 183-192 of the theme file
// Check for values for starting/ending contour plots
if "`constart`j''" == "" {
loc constart purple
}
if "`conend`j''" == "" {
loc conend orange
}
file write `scheme`j'' `"color contour_begin "`constart`j''""' _n
file write `scheme`j'' `"color contour_end "`conend`j''""' _n
file write `scheme`j'' `"color zyx2 "0 0 0""' _n(2)
file write `scheme`j'' `"color sunflower "`sunflower`j''""' _n
file write `scheme`j'' `"color sunflowerlb "0 0 0""' _n
file write `scheme`j'' `"color sunflowerlf "`sunflowerlf`j''""' _n
file write `scheme`j'' `"color sunflowerdb "0 0 0""' _n
file write `scheme`j'' `"color sunflowerdf "`sunflowerdf`j''""' _n(2)
file write `scheme`j'' `"color p gs6"' _n
} // End Loop over theme/scheme pairs
/* Add generic color loop here */
forv i = 1/`: word count `gencolor'' {
// Look up color value
mata: brewc.brewColorSearch("`: word `i' of `gencolor''")
// Loop over macros / theme/scheme file pairs
forv rfs = 1/5 {
// Add entry to scheme files
file write `scheme`rfs'' `"color p`i' "``: word `rfs' of `ctyperefs'''""' _n
} // End Loop over theme/scheme file pairs
} // End Loop for generic colors
// Loop over theme/scheme file pairs
forv j = 1/5 {
// Write blank line to scheme file
file write `scheme`j'' `""' _n
// Loop over lines 193-331 of the theme file
forv i = 193/331 {
// Write each line to the scheme file
file write `scheme`j'' `theme`j'_`i''
} // End loop over lines 193-331 of the theme file
file write `scheme`j'' `"markerstyle p1"' _n
file write `scheme`j'' `"markerstyle dots dots"' _n
file write `scheme`j'' `"markerstyle star star"' _n
file write `scheme`j'' `"markerstyle histogram histogram"' _n
file write `scheme`j'' `"markerstyle ci ci"' _n
file write `scheme`j'' `"markerstyle ci2 ci2"' _n
file write `scheme`j'' `"markerstyle ilabel ilabel"' _n
file write `scheme`j'' `"markerstyle matrix matrix"' _n
file write `scheme`j'' `"markerstyle box_marker refmarker"' _n
file write `scheme`j'' `"markerstyle editor editor"' _n
file write `scheme`j'' `"markerstyle editor_arrow ed_arrow"' _n
file write `scheme`j'' `"markerstyle sunflower sunflower"' _n(2)
// Write generic marker styles
foreach i in "" "box" "dot" "arrow" {
// Loop over cycle numbers
forv v = 1/`pcycles' {
// Add entry to scheme file
file write `scheme`j'' `"markerstyle p`v'`i' p`v'`i'"' _n
} // End Loop over cycle number
// Write blank line between each of the types
file write `scheme`j'' `""' _n
} // End Loop over marker style generic types
// Add extra space after p#arrow
file write `scheme`j'' `""' _n
// Loop over lines 332-382 of the theme file
forv i = 332/382 {
// Write each line to the scheme file
file write `scheme`j'' `theme`j'_`i''
} // End loop over lines 332-382 of the theme file
// Shade/fill settings
file write `scheme`j'' `"shadestyle foreground"' _n
file write `scheme`j'' `"shadestyle background background"' _n
file write `scheme`j'' `"shadestyle foreground foreground"' _n(2)
file write `scheme`j'' `"shadestyle ci ci"' _n
file write `scheme`j'' `"shadestyle ci2 ci2"' _n
file write `scheme`j'' `"shadestyle histogram histogram"' _n
file write `scheme`j'' `"shadestyle dendrogram dendrogram"' _n
file write `scheme`j'' `"shadestyle dotchart dotchart"' _n
file write `scheme`j'' `"shadestyle legend legend"' _n
file write `scheme`j'' `"shadestyle clegend_outer clegend_outer"' _n
file write `scheme`j'' `"shadestyle clegend_inner clegend_inner"' _n
file write `scheme`j'' `"shadestyle clegend_preg none"' _n
file write `scheme`j'' `"shadestyle plotregion plotregion"' _n
file write `scheme`j'' `"shadestyle matrix_plotregion matrix_plotregion"' _n
file write `scheme`j'' `"shadestyle sunflower sunflower"' _n
file write `scheme`j'' `"shadestyle sunflowerlb sunflowerlb"' _n
file write `scheme`j'' `"shadestyle sunflowerdb sunflowerdb"' _n
file write `scheme`j'' `"shadestyle contour_begin contour_begin"' _n
file write `scheme`j'' `"shadestyle contour_end contour_end"' _n(2)
file write `scheme`j'' `"shadestyle p foreground"' _n(2)
// Write generic marker styles
foreach i in "" "bar" "box" "pie" "area" {
// Loop over cycle numbers
forv v = 1/`pcycles' {
// Add entry to scheme file
file write `scheme`j'' `"shadestyle p`v'`i' p`v'`i'"' _n
} // End Loop over cycle number
// Spaces between graph types
if "`i'" != "area" {
// Write blank line between each of the types
file write `scheme`j'' `""' _n
} // End IF Block for other graphtypes