Dear Stateliest members,
I am making graphs with a heatplot in Stata 17.0
I created a series of heat plots and I would like to specify the range in them to be the same across the underlying z variable.
Here is one heat plot. It shows the proportion of housework wives do within couples by spousal education. The size of the circle is proportionate of the frequency of cases in the data.

I reproduced the same graph for 4 years and combined it:

The main problem with the combined graph is that the colours mean different things on each graph because the range of values plotted is different on each graph. The heat plot then reflects smallest the largest values on each graph and we get 90 as green on one graph and as purple on another one. I am looking for a way to either force the range, i.e. each graph sets colours distributed between 70% and 98% even if in a given graph the actual range is 87% to 96%. Alternatively if I could specify colours to represent specific percentages (say 96 to 98 is red, 94 to 96 is blue etc), that would also work.
Another issue is the “His education” axis labels. Is there a way to alternate them? At the moment on the combined graph they all overlap.
the variables used are:
own_shsumhousework_pc = wife's share of housework
educomp = wife's education
sp_educomp_rev = husband's education
pin_gend = sex
sure_year = survey year
Here is my code:
forvalues i = 1991(5)2006 {
#delimit;
heatplot own_shsumhousework_pc i.educomp i.sp_educomp_rev if psn_gend==0 & surv_year==`i', // not weighted
sizeprop //sizeprop scales the size of the color fields in proportion to the relative frequency of the underlying data
colors(viridis, intensity(0.8) reverse)
scatter(circle)
values(format(%9.0f) label(own_shsumhousework_pc) size(vsmall))
xlabel(, nogrid tlcolor(none) tposition(crossing) labsize(vsmall)) xscale(lcolor(none) alt)
ylabel(, nogrid tlcolor(none) tposition(crossing) labsize(vsmall)) yscale(lcolor(none))
ytitle("{bf:Her education}") xtitle("{bf:His education}")
p(lalign(inside) lwidth(vthin) msize(large))
graphregion(color(white))
legend(subtitle("Housework" "share"))
addplot(function y = 1.5, range(0.5 4.5) lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 2.5, range(0.5 4.5) lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 3.5, range(0.5 4.5) lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 1.5, range(0.5 4.5) horizontal lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 2.5, range(0.5 4.5) horizontal lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 3.5, range(0.5 4.5) horizontal lcolor(gs14) lpattern(solid) lwidth(thin)
)
text(4.6 -0.36 "`i'", size(small) /*margin(0 0 0 0)*/ justification(left))
;
#delimit cr
graph save "$FigTemp/hwsh_edu_`i'", replace
graph export "$FigTemp/hwsh_edu_`i'.png", replace
}
graph combine "$FigTemp/hwsh_edu_1991" "$FigTemp/hwsh_edu_1996" "$FigTemp/hwsh_edu_2001" "$FigTemp/hwsh_edu_2006"
graph save "$FigTemp/hwsh_edu_comb", replace
graph export "$FigTemp/hwsh_edu_comb.png", replace
I'd be grateful for any advice,
Thank you,
Ekaterina
I am making graphs with a heatplot in Stata 17.0
I created a series of heat plots and I would like to specify the range in them to be the same across the underlying z variable.
Here is one heat plot. It shows the proportion of housework wives do within couples by spousal education. The size of the circle is proportionate of the frequency of cases in the data.
I reproduced the same graph for 4 years and combined it:
The main problem with the combined graph is that the colours mean different things on each graph because the range of values plotted is different on each graph. The heat plot then reflects smallest the largest values on each graph and we get 90 as green on one graph and as purple on another one. I am looking for a way to either force the range, i.e. each graph sets colours distributed between 70% and 98% even if in a given graph the actual range is 87% to 96%. Alternatively if I could specify colours to represent specific percentages (say 96 to 98 is red, 94 to 96 is blue etc), that would also work.
Another issue is the “His education” axis labels. Is there a way to alternate them? At the moment on the combined graph they all overlap.
the variables used are:
own_shsumhousework_pc = wife's share of housework
educomp = wife's education
sp_educomp_rev = husband's education
pin_gend = sex
sure_year = survey year
Here is my code:
forvalues i = 1991(5)2006 {
#delimit;
heatplot own_shsumhousework_pc i.educomp i.sp_educomp_rev if psn_gend==0 & surv_year==`i', // not weighted
sizeprop //sizeprop scales the size of the color fields in proportion to the relative frequency of the underlying data
colors(viridis, intensity(0.8) reverse)
scatter(circle)
values(format(%9.0f) label(own_shsumhousework_pc) size(vsmall))
xlabel(, nogrid tlcolor(none) tposition(crossing) labsize(vsmall)) xscale(lcolor(none) alt)
ylabel(, nogrid tlcolor(none) tposition(crossing) labsize(vsmall)) yscale(lcolor(none))
ytitle("{bf:Her education}") xtitle("{bf:His education}")
p(lalign(inside) lwidth(vthin) msize(large))
graphregion(color(white))
legend(subtitle("Housework" "share"))
addplot(function y = 1.5, range(0.5 4.5) lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 2.5, range(0.5 4.5) lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 3.5, range(0.5 4.5) lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 1.5, range(0.5 4.5) horizontal lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 2.5, range(0.5 4.5) horizontal lcolor(gs14) lpattern(solid) lwidth(thin) ||
function y = 3.5, range(0.5 4.5) horizontal lcolor(gs14) lpattern(solid) lwidth(thin)
)
text(4.6 -0.36 "`i'", size(small) /*margin(0 0 0 0)*/ justification(left))
;
#delimit cr
graph save "$FigTemp/hwsh_edu_`i'", replace
graph export "$FigTemp/hwsh_edu_`i'.png", replace
}
graph combine "$FigTemp/hwsh_edu_1991" "$FigTemp/hwsh_edu_1996" "$FigTemp/hwsh_edu_2001" "$FigTemp/hwsh_edu_2006"
graph save "$FigTemp/hwsh_edu_comb", replace
graph export "$FigTemp/hwsh_edu_comb.png", replace
I'd be grateful for any advice,
Thank you,
Ekaterina
Comment