I feel like I should know how to do this - but I'm trying to plot two variables with two sets of over groups. The way the graphs come out, the bars of the two variables are next to each other, within the over groups. But what I would like is for all the bars of each variable to be next to each other within the first over group. In case this sounds vague, I've included code and the resulting graph below.
HTML Code:
clear all set obs 12 set seed 123456 gen year = . replace year = 2009 in 1/4 replace year = 2013 in 5/8 replace year = 2017 in 9/12 gen color = "" replace color = "Red" if inlist(_n, 1, 5, 9) replace color = "Blue" if inlist(_n, 2, 6, 10) replace color = "Orange" if inlist(_n, 3, 7, 11) replace color = "Green" if inlist(_n, 4, 8, 12) gen percent_favorite = . replace percent_favorite = rnormal(.29, .05) if color=="Red" replace percent_favorite = rnormal(.41, .05) if color=="Blue" replace percent_favorite = rnormal(.13, .05) if color=="Orange" egen total = total(percent_favorite), by(year) replace percent_favorite = 1 - total if color=="Green" drop total gen percent_least_favorite = . replace percent_least_favorite = rnormal(.15, .05) if color=="Red" replace percent_least_favorite = rnormal(.11, .05) if color=="Blue" replace percent_least_favorite = rnormal(.42, .05) if color=="Orange" egen total = total(percent_least_favorite), by(year) replace percent_least_favorite = 1 - total if color=="Green" drop total graph bar percent_favorite percent_least_favorite, over(year) over(color) scheme(538) legend(pos(6) rows(1))
Array
Basically - I would like all of the mean of percent_favorite bars for each year to be next to each other within the Blue group and then the mean of percent_least_favorite within the blue group next to each other. I tried asyvars, but it doesn't work. So I'm stumped. Any help would be greatly appreciated.
0 Response to How to rearrange bars in bar graph with two variables and two over groups
Post a Comment