Graph Stata中图形的一致条形图颜色

Graph Stata中图形的一致条形图颜色,graph,stata,Graph,Stata,我在Stata中输出堆叠的条形图,每个堆叠的条形图从底部->向上:最大->最小,每个团队赢% clear set obs 10 gen team = "yankees" if inlist(_n, 1, 6) replace team = "red sox" if inlist(_n, 2, 7) replace team = "mets" if inlist(_n, 3, 8) replace team = "nationals" if inlist(_n, 4, 9) replace

我在Stata中输出堆叠的条形图,每个堆叠的条形图从底部->向上:最大->最小,每个团队赢%

clear
set obs 10
gen team = "yankees" if inlist(_n, 1, 6) 
replace team = "red sox" if inlist(_n, 2, 7) 
replace team = "mets" if inlist(_n, 3, 8) 
replace team = "nationals" if inlist(_n, 4, 9) 
replace team = "astros" if inlist(_n, 5, 10) 
gen wins = -10 + 20 * _n 
replace wins = wins[11 - _n] in 6/10 
gen year = cond(_n <= 5, 2013, 2014) 
gen season = "regular" in 1/10

set obs 16
replace team = "yankees" if inlist(_n, 11, 14)
replace team = "red sox" if inlist(_n, 12, 15)
replace team = "astros" if inlist(_n, 13) 
replace team = "mets" if inlist(_n, 16) 
replace wins = -10 + 30 * (_n-10) in 11/16
replace wins = wins[17 - _n] in 14/16 
replace year = 2013 in 11/13
replace year = 2014 in 14/16
replace season = "playoffs" in 11/16

foreach x in "regular" "playoffs"{
   preserve
   keep if season == "`x'"
   #delimit ;
   graph bar (mean) wins, over(team, sort(1) descending) over(year, label(ticks labs(small))) asyvars stack 
     ytitle("Wins (%)")
     title("Wins Percentages in `x'")
     blabel(bar, position(center) format(%9.0f) size(2.5) color(white))
     legend(size(2) rowgap(*.45) pos(6) rows (2) region(style(legend) fcolor(gs15) margin(medsmall)) colgap(*.75) symxsize(*.75) keygap(*.33));
    #delimit cr
   restore
清除
设置obs 10
gen team=“yankees”如果在列表中(\n,1,6)
如果在列表中(\n,2,7),则替换team=“red sox”
如果在列表中(\n,3,8),则替换team=“mets”
如果在列表中(\n,4,9),则替换team=“nations”
如果在列表中(\n,5,10),则替换team=“astros”
gen wins=-10+20*\n
替换wins=6/10中的wins[11-\n]

gen year=cond(_n这只是一个部分答案,如果其他人或我可以进一步回答,则需要补充

以您的沙盒为例,以对您的问题不重要的方式重写代码

clear
set obs 10
gen team = "yankees" if inlist(_n, 1, 6) 
replace team = "red sox" if inlist(_n, 2, 7) 
replace team = "mets" if inlist(_n, 3, 8) 
replace team = "nationals" if inlist(_n, 4, 9) 
replace team = "astros" if inlist(_n, 5, 10) 
gen wins = -10 + 20 * _n 
replace wins = wins[11 - _n] in 6/10 
gen year = cond(_n <= 5, 2013, 2014) 

#delimit ;
graph bar (mean) wins, over(team, sort(1) descending) over(year, label(ticks labs(small))) asyvars stack 
  ytitle("Wins (%)")
  title("Wins")
  blabel(bar, position(center) format(%9.0f) size(2.5) color(white))
  legend(size(2) rowgap(*.45) pos(6) rows (2) region(style(legend) fcolor(gs15) margin(medsmall)) colgap(*.75) symxsize(*.75) keygap(*.33));
#delimit cr
这样就可以生成这种图形:

graph hbar (asis) wins? , over(team) over(year) nofill legend(off)

这可能是你更复杂的问题的一个更好的基础。(我不确定我们是否期望了解棒球奥卡纳。确实,这是棒球吗?这些细节不是普遍理解的)< <
我个人的观点是,条形图的堆叠会使图表变得更糟,但这是一个不同的问题。

重新构造,使每个团队都是一个单独的变量,然后您可以将条形图与变量相关联。为了更好地回答,请举一个可重复的问题示例。我们不能使用您的数据。我已修改为包含样本数据。(假设这是一个循环的一部分,因为有另一个变量将昼夜比赛、双标题等分解为不同的类别,每个类别都有自己的图表,以了解如果大都会队不打双标题,并且被排除在单独的图表之外,字母表中紧随其后的每支球队将有不同的颜色,)我再次修改以显示循环尼克,我再次修改以将循环包含在数据中。总的来说,我同意堆叠条不是最好的,尽管对于我拥有的更复杂的数据(我正试图用这些人为的棒球数据简化),我相信堆叠条是最好的。非常感谢您的帮助!
graph hbar (asis) wins? , over(team) over(year) nofill legend(off)