经管之家送您一份
应届毕业生专属福利!
求职就业群
感谢您参与论坛问题回答
经管之家送您两个论坛币!
+2 论坛币
brewscheme 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, 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 available in Stata. Additionally, as a way of creating a centralized source for the Stata community to work from, palettes from outside of ColorBrewer are being added to boost the capabilities of the program. - *<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Brewscheme>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ssc inst brewscheme
- // Dataset
- webuse grunfeld, clear //getting data online
- keep if company == 1
- keep if year < 1945
- generate year2 = year + 0.3
- generate year3 = year - 0.3
- generate average = (invest + mvalue + kstock) / 3
- // Make a simple graph using Stata defaults
- twoway bar invest year3 , barw(0.3) || ///
- bar mvalue year , barw(0.3) || ///
- bar kstock year2 , barw(0.3) || ///
- line average year , scheme(s2color) name(stata, replace)
- *(Nick Cox - Stata list, 13/4/11)
- *-----------Ex 1. Single color palette for all graphs
- // Create a new scheme file for all graph types
- brewscheme, scheme(test) allstyle(dark2) allcolor(7)
- // Make the same graph using the scheme file you just created
- twoway bar invest year3, barw(0.3) || ///
- bar mvalue year , barw(0.3) || ///
- bar kstock year2, barw(0.3) || ///
- line average year , name(brewscheme1, replace) scheme(test)
- *-----------Ex 2. Distinct Color Palette for Bar Graphs with Default Color Palette for All Other Graphs
- brewscheme, scheme(mixed1) barst(pastel1) somest(brbg)
- twoway bar invest year3, barw(0.3) || ///
- bar mvalue year , barw(0.3) || ///
- bar kstock year2, barw(0.3) || ///
- line average year , name(brewscheme2, replace) scheme(mixed1)
- *-----------Ex 3. Distinct Color Palette for Each Graph Type.
- brewscheme, scheme(test2) barst(paired) barc(12) dotst(prgn) dotc(7) ///
- scatstyle(set1) scatc(9) linest(pastel2) linec(8) boxstyle(accent) boxc(8) ///
- areast(dark2) areac(8) piest(mdepoint) sunst(greys) histst(veggiese) ///
- cist(activitiesa) matst(spectral) reflst(purd) refmst(set3) const(ylgn) ///
- cone(puor)
- twoway bar invest year3, barw(0.3) || ///
- bar mvalue year , barw(0.3) || ///
- bar kstock year2, barw(0.3) || ///
- line average year , name(brewscheme3, replace) scheme(test2)
复制代码 |
1. 更多用法可参考Brewing color schemes in Stata:Making it easier for end users to customize Stata graphs
一文及help brewscheme
2. 常有网友问及如何去除stata绘图背景色,brewscheme可以作为较为快速的一种参考方法
- // Make a simple graph using Stata defaults
- sysuse auto,clear
- gr box price, over(rep78) name(stata1, replace)
- // Make the same graph using the scheme file you just created
- gr box price, over(rep78) asyvars scheme(test2) name(brewscheme, replace)
复制代码
注意图中box颜色 - // Load the auto data set
- sysuse auto, clear
- // Create a new scheme file for all graph types (此处为scheme(test))
- brewscheme, scheme(test) allstyle(dark2) allcolor(7)
- // Make a simple graph using s1color(命名stata)
- tw scatter mpg length || lfit mpg length, name(stata, replace)
- // Make the same graph using the scheme file you just created (scheme(test),命名brewscheme)
- tw scatter mpg length || lfit mpg length, scheme(test) name(brewscheme, replace)
复制代码
- brewscheme, scheme(ggtest2) const(orange) cone(blue) consat(20) ///
- scatst(ggplot2) scatc(5) piest(ggplot2) piec(6) barst(ggplot2) barc(2) ///
- linest(ggplot2) linec(2) areast(ggplot2) areac(5) somest(ggplot2) somec(24) ///
- cist(ggplot2) cic(3)
- sysuse auto.dta, clear
- #d;
- tw lowess mpg weight, || scatter mpg weight if rep78 == 1 ||
- scatter mpg weight if rep78 == 2 || scatter mpg weight if rep78 == 3 ||
- scatter mpg weight if rep78 == 4 || scatter mpg weight if rep78 == 5,
- scheme(ggtest2) legend(order(2 "Repair Record = 1"
- 3 "Repair Record = 2" 4 "Repair Record = 3"
- 5 "Repair Record = 4" 6 "Repair Record = 5"));
- #d cr
复制代码
- //The Bad
- sysuse nlsw88.dta, clear
- tw scatter wage ttl_exp if industry == 11 || scatter wage ///
- ttl_exp if industry == 4 || scatter wage ttl_exp if ///
- industry == 6 || scatter wage ttl_exp if industry == 7, ///
- ti("Not so Simple Scatterplot", c(black) span ///
- size(medlarge)) scheme(s2color) name( bad,replace)
- //The Ugly
- sysuse nlsw88.dta, clear
- #d;
- tw scatter wage ttl_exp if industry == 11, mc(red)
- mlc(black) mlw(vthin) msize(medsmall) || scatter
- wage ttl_exp if industry == 4, mc(orange) mlc(black)
- mlw(vthin) msize(medsmall) || scatter wage ttl_exp
- if industry == 6, mc(yellow) mlc(black) mlw(vthin)
- msize(medsmall) || scatter wage ttl_exp if industry
- == 7, mc(green) mlc(black) mlw(vthin)
- msize(medsmall) ylab(#10, angle(0) nogrid)
- legend(pos(12) span label(1 "Professional") label(2
- "Manufacturing") label(3 "Wholesale/Retail") label(4
- "Fin./Insure/Real Estate") rows(1) region(lc(white)
- fc(white) ic(white)) size(medsmall) symy(2.5)
- symx(2.5)) graphr(ic(white) fc(white) lc(white))
- plotr(ic(white) fc(white) lc(white)) xlab(#7)
- ti("Not so Simple Scatterplot", c(black) span
- size(medlarge)) name(ugly ,replace);
- #d cr
- //One palette to rule them all
- brewscheme, scheme(onePaletteToRuleThemAll) allst(mdebar) allc(5)
- sysuse nlsw88.dta, clear
- #d;
- tw scatter wage ttl_exp if industry == 11 || scatter wage
- ttl_exp if industry == 4 || scatter wage ttl_exp if
- industry == 6 || scatter wage ttl_exp if industry == 7,
- ti("Not so Simple Scatterplot")
- scheme(onePaletteToRuleThemAll) legend(label(1
- "Professional") label(2 "Manufacturing") label(3
- "Wholesale/Retail") label(4 "Fin./Insure/Real Estate"))
- name(g1,replace);
- #d cr
- /*Sometimes, you may want to include other plots that help
- to summarize the patterns in the data*/
- sysuse nlsw88.dta, clear
- #d;
- tw scatter wage ttl_exp if industry == 11 || scatter wage
- ttl_exp if industry == 4 || scatter wage ttl_exp if
- industry == 6 || scatter wage ttl_exp if industry == 7 ||
- lfitci wage ttl_exp if industry == 11, ti("Not so Simple
- Scatterplot") scheme(onePaletteToRuleThemAll) legend(label(1
- "Professional") label(2 "Manufacturing") label(3
- "Wholesale/Retail") label(4 "Fin./Insure/Real Estate")
- rows(2)) name(g2,replace) ;
- #d cr
复制代码
- sysuse nlsw88.dta, clear
- #d;
- tw scatter wage ttl_exp if industry == 11 || scatter wage
- ttl_exp if industry == 4 || scatter wage ttl_exp if
- industry == 6 || scatter wage ttl_exp if industry == 7 ||
- lfitci wage ttl_exp if industry == 11, ti("Not so Simple
- Scatterplot") scheme(test2) legend(label(1
- "Professional") label(2 "Manufacturing") label(3
- "Wholesale/Retail") label(4 "Fin./Insure/Real Estate")
- rows(2)) name(g2,replace) ;
- #d cr
复制代码
- brewscheme, scheme(myriadColorPalettes) barst(paired) ///
- barc(12) dotst(prgn) dotc(7) scatstyle(set1) scatc(9) ///
- linest(pastel2) linec(8) boxstyle(accent) boxc(8) ///
- areast(dark2) areac(8) piest(mdepoint) sunst(greys) ///
- histst(veggiese) cist(activitiesa) matst(spectral) ///
- reflst(purd) refmst(set3) const(ylgn) cone(puor)
- sysuse nlsw88.dta, clear
- #d;
- tw scatter wage ttl_exp if industry == 11 || scatter wage
- ttl_exp if industry == 4 || scatter wage ttl_exp if
- industry == 6 || scatter wage ttl_exp if industry == 7 ||
- lfitci wage ttl_exp if industry == 11, ti("Not so Simple
- Scatterplot") scheme(myriadColorPalettes) legend(label(1
- "Professional") label(2 "Manufacturing") label(3
- "Wholesale/Retail") label(4 "Fin./Insure/Real Estate")
- rows(2)) name(g2,replace) ;
- #d cr
复制代码
|
扫码加我 拉你入群
请注明:姓名-公司-职位
以便审核进群资格,未注明则拒绝
|