楼主: 匿名
3643 8

[Stata] - brewscheme-自定义绘图方案 [推广有奖]

匿名网友
楼主
匿名网友  发表于 2015-12-9 21:31:32 |坛友微信交流群|倒序 |AI写论文
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

Brewscheme

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.
  1. *<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Brewscheme>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2. ssc inst brewscheme
  3. // Dataset

  4. webuse grunfeld, clear   //getting data online
  5. keep if company == 1
  6. keep if year < 1945

  7. generate year2 = year + 0.3
  8. generate year3 = year - 0.3

  9. generate average = (invest + mvalue + kstock) / 3

  10. // Make a simple graph using Stata defaults
  11. twoway  bar invest year3 , barw(0.3)  || ///
  12.        bar mvalue year  , barw(0.3)  || ///
  13.        bar kstock year2 , barw(0.3)  || ///
  14.        line average year , scheme(s2color) name(stata, replace)
  15. *(Nick Cox - Stata list,  13/4/11)

  16. *-----------Ex 1. Single color palette for all graphs

  17. // Create a new scheme file for all graph types
  18. brewscheme, scheme(test) allstyle(dark2) allcolor(7)

  19. // Make the same graph using the scheme file you just created
  20. twoway bar invest year3, barw(0.3) || ///
  21.        bar mvalue year , barw(0.3) || ///
  22.        bar kstock year2, barw(0.3) || ///
  23.        line average year , name(brewscheme1, replace) scheme(test)


  24. *-----------Ex 2. Distinct Color Palette for  Bar Graphs with Default Color Palette for All Other Graphs
  25. brewscheme, scheme(mixed1) barst(pastel1) somest(brbg)


  26.   twoway bar invest year3, barw(0.3) || ///
  27.         bar mvalue year , barw(0.3) || ///
  28.         bar kstock year2, barw(0.3) || ///
  29.         line average year , name(brewscheme2, replace) scheme(mixed1)


  30. *-----------Ex 3. Distinct Color Palette for Each Graph Type.

  31. brewscheme, scheme(test2) barst(paired) barc(12) dotst(prgn) dotc(7) ///   
  32. scatstyle(set1) scatc(9) linest(pastel2) linec(8) boxstyle(accent) boxc(8)  ///   
  33. areast(dark2) areac(8) piest(mdepoint) sunst(greys) histst(veggiese)   ///   
  34. cist(activitiesa) matst(spectral) reflst(purd) refmst(set3) const(ylgn)  ///   
  35. cone(puor)

  36. twoway bar invest year3, barw(0.3) || ///
  37.        bar mvalue year , barw(0.3) || ///
  38.        bar kstock year2, barw(0.3) || ///
  39.        line average year , name(brewscheme3, replace) scheme(test2)
复制代码

stata.png


brewscheme1.png


brewscheme2.png


brewscheme3.png


         
  1.  更多用法可参考Brewing color schemes in Stata:Making it easier for end users to customize Stata graphs
一文及help brewscheme               
  2.  常有网友问及如何去除stata绘图背景色,brewscheme可以作为较为快速的一种参考方法

  1. // Make a simple graph using Stata defaults
  2. sysuse auto,clear   
  3. gr box price, over(rep78) name(stata1, replace)

  4. // Make the same graph using the scheme file you just created
  5. gr box price, over(rep78) asyvars scheme(test2) name(brewscheme, replace)
复制代码

stata1.png


brewscheme4.png

注意图中box颜色

  1. // Load the auto data set
  2. sysuse auto, clear

  3. // Create a new scheme file for all graph types (此处为scheme(test))
  4. brewscheme, scheme(test) allstyle(dark2) allcolor(7)

  5. // Make a simple graph using s1color(命名stata)
  6. tw scatter mpg length || lfit mpg length, name(stata, replace)

  7. // Make the same graph using the scheme file you just created (scheme(test),命名brewscheme)
  8. tw scatter mpg length || lfit mpg length, scheme(test) name(brewscheme, replace)
复制代码

stata.png


brewscheme.png

  1. brewscheme, scheme(ggtest2) const(orange) cone(blue) consat(20)  ///  
  2. scatst(ggplot2) scatc(5) piest(ggplot2) piec(6) barst(ggplot2) barc(2)   ///   
  3. linest(ggplot2) linec(2) areast(ggplot2) areac(5) somest(ggplot2) somec(24) ///   
  4. cist(ggplot2) cic(3)

  5. sysuse auto.dta, clear

  6. #d;
  7. tw lowess mpg weight, || scatter mpg weight if rep78 == 1 ||        
  8. scatter mpg weight if rep78 == 2 || scatter mpg weight if rep78 == 3 ||        
  9. scatter mpg weight if rep78 == 4 || scatter mpg weight if rep78 == 5,        
  10. scheme(ggtest2) legend(order(2 "Repair Record = 1"         
  11. 3 "Repair Record = 2" 4 "Repair Record = 3"         
  12. 5 "Repair Record = 4" 6 "Repair Record = 5"));
  13. #d cr
复制代码

ggtest2.png

  1. //The Bad
  2. sysuse nlsw88.dta, clear
  3. tw scatter wage ttl_exp if industry == 11 || scatter wage ///
  4. ttl_exp if industry == 4 || scatter wage ttl_exp if ///
  5. industry == 6 || scatter wage ttl_exp if industry == 7, ///
  6. ti("Not so Simple Scatterplot", c(black) span ///
  7. size(medlarge)) scheme(s2color) name( bad,replace)



  8. //The Ugly
  9. sysuse nlsw88.dta, clear
  10. #d;
  11. tw scatter wage ttl_exp if industry == 11, mc(red)
  12. mlc(black) mlw(vthin) msize(medsmall) || scatter
  13. wage ttl_exp if industry == 4, mc(orange) mlc(black)
  14. mlw(vthin) msize(medsmall) || scatter wage ttl_exp
  15. if industry == 6, mc(yellow) mlc(black) mlw(vthin)
  16. msize(medsmall) || scatter wage ttl_exp if industry
  17. == 7, mc(green) mlc(black) mlw(vthin)
  18. msize(medsmall) ylab(#10, angle(0) nogrid)
  19. legend(pos(12) span label(1 "Professional") label(2
  20. "Manufacturing") label(3 "Wholesale/Retail") label(4
  21. "Fin./Insure/Real Estate") rows(1) region(lc(white)
  22. fc(white) ic(white)) size(medsmall) symy(2.5)
  23. symx(2.5)) graphr(ic(white) fc(white) lc(white))
  24. plotr(ic(white) fc(white) lc(white)) xlab(#7)
  25. ti("Not so Simple Scatterplot", c(black) span
  26. size(medlarge)) name(ugly ,replace);
  27. #d cr


  28. //One palette to rule them all

  29. brewscheme, scheme(onePaletteToRuleThemAll) allst(mdebar) allc(5)

  30. sysuse nlsw88.dta, clear
  31. #d;
  32. tw scatter wage ttl_exp if industry == 11 || scatter wage
  33. ttl_exp if industry == 4 || scatter wage ttl_exp if  
  34. industry == 6 || scatter wage ttl_exp if industry == 7,
  35. ti("Not so Simple Scatterplot")   
  36. scheme(onePaletteToRuleThemAll) legend(label(1
  37. "Professional") label(2 "Manufacturing") label(3
  38. "Wholesale/Retail") label(4 "Fin./Insure/Real Estate"))
  39. name(g1,replace);
  40. #d cr


  41. /*Sometimes, you may want to include other plots that help
  42. to summarize the patterns in the data*/

  43. sysuse nlsw88.dta, clear
  44. #d;
  45. tw scatter wage ttl_exp if industry == 11 || scatter wage
  46. ttl_exp if industry == 4 || scatter wage ttl_exp if
  47. industry == 6 || scatter wage ttl_exp if industry == 7 ||
  48. lfitci wage ttl_exp if industry == 11, ti("Not so Simple
  49. Scatterplot") scheme(onePaletteToRuleThemAll) legend(label(1
  50. "Professional") label(2 "Manufacturing") label(3
  51. "Wholesale/Retail") label(4 "Fin./Insure/Real Estate")
  52. rows(2)) name(g2,replace) ;
  53. #d cr
复制代码

bad.png


ugly.png


g1.png


g2.png

  1. sysuse nlsw88.dta, clear
  2. #d;
  3. tw scatter wage ttl_exp if industry == 11 || scatter wage
  4. ttl_exp if industry == 4 || scatter wage ttl_exp if
  5. industry == 6 || scatter wage ttl_exp if industry == 7 ||
  6. lfitci wage ttl_exp if industry == 11, ti("Not so Simple
  7. Scatterplot") scheme(test2) legend(label(1
  8. "Professional") label(2 "Manufacturing") label(3
  9. "Wholesale/Retail") label(4 "Fin./Insure/Real Estate")
  10. rows(2)) name(g2,replace) ;
  11. #d cr
复制代码

g2.PNG



  1. brewscheme, scheme(myriadColorPalettes) barst(paired) ///
  2. barc(12) dotst(prgn) dotc(7) scatstyle(set1) scatc(9) ///
  3. linest(pastel2) linec(8) boxstyle(accent) boxc(8)    ///
  4. areast(dark2) areac(8) piest(mdepoint) sunst(greys) ///
  5. histst(veggiese) cist(activitiesa) matst(spectral) ///
  6. reflst(purd) refmst(set3) const(ylgn) cone(puor)  

  7. sysuse nlsw88.dta, clear
  8. #d;
  9. tw scatter wage ttl_exp if industry == 11 || scatter wage
  10. ttl_exp if industry == 4 || scatter wage ttl_exp if
  11. industry == 6 || scatter wage ttl_exp if industry == 7 ||
  12. lfitci wage ttl_exp if industry == 11, ti("Not so Simple
  13. Scatterplot") scheme(myriadColorPalettes) legend(label(1
  14. "Professional") label(2 "Manufacturing") label(3
  15. "Wholesale/Retail") label(4 "Fin./Insure/Real Estate")
  16. rows(2)) name(g2,replace) ;
  17. #d cr
复制代码

g8.png





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Scheme BREW REW EME bre average company getting simple invest

已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 2 + 2 + 2 精彩帖子
xddlovejiao1314 + 100 + 100 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 100  论坛币 + 100  学术水平 + 7  热心指数 + 7  信用等级 + 7   查看全部评分

沙发
刘锦钥 发表于 2015-12-9 21:42:49 来自手机 |只看作者 |坛友微信交流群
niuniuyiwan 发表于 2015-12-9 21:31
占座学习
已有 1 人评分热心指数 收起 理由
niuniuyiwan + 4 精彩帖子

总评分: 热心指数 + 4   查看全部评分

使用道具

藤椅
刘锦钥 发表于 2015-12-9 21:42:52 来自手机 |只看作者 |坛友微信交流群
niuniuyiwan 发表于 2015-12-9 21:31
占座学习

使用道具

板凳
xddlovejiao1314 学生认证  发表于 2015-12-9 22:12:36 来自手机 |只看作者 |坛友微信交流群
niuniuyiwan 发表于 2015-12-9 21:31
感谢分享~
已有 1 人评分热心指数 收起 理由
niuniuyiwan + 5 热心帮助其他会员

总评分: 热心指数 + 5   查看全部评分

使用道具

报纸
Yanis100405 学生认证  发表于 2016-6-3 10:29:35 |只看作者 |坛友微信交流群
创建新的scheme,但是总是报错,求解答
brewscheme, scheme(set1) allst(set1) allc(5) allsat(80)

file D:\Program Files (x86)\Stata14\ado\personal/brewcolors/colordb.dta not found
                 stata():  3598  Stata returned error
       brewcolors::new():     -  function returned error
            brewcolors():     -  function returned error
                 <istmt>:     -  function returned error

使用道具

地板
niuniuyiwan 在职认证  发表于 2016-6-4 16:58:36 |只看作者 |坛友微信交流群
Yanis100405 发表于 2016-6-3 10:29
创建新的scheme,但是总是报错,求解答
brewscheme, scheme(set1) allst(set1) allc(5) allsat(80)
输入:
  1. brewcolordb, replace
复制代码
然后回车

使用道具

7
Yanis100405 学生认证  发表于 2016-6-5 15:18:44 |只看作者 |坛友微信交流群
niuniuyiwan 发表于 2016-6-4 16:58
输入:然后回车
谢谢

使用道具

8
caesarljs 在职认证  学生认证  发表于 2016-10-31 15:28:27 |只看作者 |坛友微信交流群
niuniuyiwan 发表于 2016-6-4 16:58
输入:然后回车
你好,请教一下高手,请问我运行的时候总是提示找不到文件是什么情况啊?(note: scheme onePaletteToRuleThemAll not found, using s2color),另外运行你说的这个 brewlordb,replace,提示file c:\ado\personal/brewcolors/colordb.dta could not be opened,不知道为什么,请大侠指点,十分感谢

使用道具

9
caesarljs 在职认证  学生认证  发表于 2016-11-1 11:11:54 |只看作者 |坛友微信交流群
. gr box price, over(rep78) asyvars scheme(test2) name(brewscheme, replace)
(note: scheme test2 not found, using s2color)
请问这是什么情况啊 请求高手指导,谢谢

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-19 10:53