Context : I want to display the industry distribution within 3 age categories (relative to total employment in each age category), and show this for men and women in a combined way (left and right hand side).
My problem is the following: the y-axis labels are repeated and eat up a lot of space.
My objective: ideally, deleting these labels on the right-hand side plot only.
What I have done: I have almost successfully used catplot, either in combination with graph combine, or with the by() option. However, in either versions, I would like to delete the repeated y-axis labels of the right-hand side graph, that unnecessarily eat up a lot of space (in my opinion).
Code:
ssc install catplot ssc install tabplot ssc install grc1leg ** OPTION 1 #delimit ; catplot agecat industry if gender==1, percent(agecat) var1opts(label(nolabels)) graphregion(color(white)) l1title("") title("Men") legend(label(1 "18-34") label(2 "35-59 ") label(3 "60-64 ")) asyvars bar(1, color(gs14)) bar(2, color(gs8)) bar(3, color(gs3)) saving("$fgs/part1.gph", replace) ; #delimit cr #delimit ; catplot agecat industry if gender==2, percent(agecat) var1opts(label(nolabels)) graphregion(color(white)) l1title("") title("Women") legend(label(1 "18-34") label(2 "35-59 ") label(3 "60-64 ")) asyvars bar(1, color(gs14)) bar(2, color(gs8)) bar(3, color(gs3)) saving("part2.gph", replace) ; #delimit cr grc1leg "part1" "part2", graphregion(color(white))
Array
Code:
** OPTION 2 #delimit ; catplot agecat industry , percent(agecat gender) by(gender, style(combine) graphregion(color(white)) plotregion(color(white))) var1opts(label(nolabels)) graphregion(color(white)) asyvars bar(1, color(gs14)) bar(2, color(gs8)) bar(3, color(gs3)) legend(label(1 "18-34") label(2 "35-59") label(3 "60-64")) ; #delimit cr
Array
What I have also tried: After reading a few Stata list posts (and notably a recent suggestion here: https://www.statalist.org/forums/for...ts-for-catplot) I have tried turning to tabplot, and that successfully took care of the y-axis labels problem; but another problem has arisen, which is that I am unable to display the relevant horizontal bars next to each other.
Code:
#delimit ; tabplot industry agecat, percent(agecat gender) by(gender, graphregion(color(white)) plotregion(color(white)) ) subtitle(,fcolor(white) bcolor(white)) graphregion(color(white)) horizontal separate(agecat) bar1(color(gs14)) bar2(color(gs8)) bar3(color(gs3)) ytitle("") xtitle("Age categories") xlabel(1 "18-34" 2 "35-59 " 3 "60-64 ") legend(label(1 "18-34") label(2 "35-59") label(3 "60-64")) ; #delimit cr
Array
Would you be able to help? I hope the desired output is clear: similar to the catplot output, without the y-labels on the right-hand side plot.
A working data example is below. To reduce the total size of the post I have restricted it to 100 obs, the real data much larger data (the 100 sample size makes the distribution very noisy and somewhat weird, but the problem remains the same - ylabels).
With my deepest gratitude,
Paul
(uses Stata 15.1 or earlier versions)
---
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(gender industry) float(emp agecat) 1 6 1 18 2 10 1 35 2 1 1 35 2 6 1 18 1 6 1 18 1 1 1 35 1 1 1 35 2 9 1 35 1 1 1 35 1 7 1 35 2 1 1 35 2 3 1 35 1 1 1 18 1 7 1 18 2 9 1 18 2 6 1 35 1 7 1 18 1 6 1 18 1 7 1 35 2 1 1 35 1 1 1 18 1 1 1 35 2 6 1 35 2 10 1 35 2 9 1 18 2 10 1 35 2 8 1 35 1 6 1 18 1 6 1 18 1 1 1 35 2 6 1 35 1 1 1 18 2 6 1 18 1 7 1 35 2 8 1 35 1 1 1 35 1 4 1 18 2 6 1 18 1 9 1 35 1 5 1 35 2 6 1 35 1 6 1 35 1 10 1 35 1 3 1 18 1 1 1 35 1 6 1 35 2 9 1 35 2 10 1 18 1 1 1 35 1 1 1 35 1 6 1 35 1 3 1 35 1 1 1 35 2 10 1 35 1 9 1 18 2 3 1 18 1 3 1 18 2 1 1 18 1 1 1 18 2 6 1 18 2 6 1 18 2 10 1 18 1 6 1 35 2 1 1 35 2 6 1 35 2 8 1 18 1 1 1 18 2 6 1 18 2 1 1 18 2 6 1 35 1 5 1 35 2 1 1 18 2 1 1 35 2 1 1 35 1 6 1 35 2 7 1 18 2 8 1 35 1 1 1 35 2 1 1 35 2 10 1 35 1 5 1 60 1 5 1 35 2 6 1 18 1 10 1 35 2 6 1 18 1 9 1 35 2 9 1 35 2 5 1 35 1 6 1 18 1 1 1 35 2 6 1 35 2 6 1 35 2 6 1 35 2 3 1 18 2 1 1 18 2 6 1 35 1 7 1 18 2 1 1 18 1 9 1 18 1 3 1 35 end label values gender s label def s 1 "Men", modify label def s 2 "Women", modify label values industry i label def i 1 "Agriculture", modify label def i 3 "Manufacturing", modify label def i 4 "Utilities", modify label def i 5 "Construction", modify label def i 6 "Trade", modify label def i 7 "Transport", modify label def i 8 "Finance", modify label def i 9 "Services", modify label def i 10 "Domestic Services", modify
0 Response to Problem deleting common y-axis in catplot with by() option
Post a Comment