I want to add a text with an angle to my twoway graph, which I achieve by using addplot: scatteri (...). However, this overrides my legend. If I specify legend(off) in the addplot: (...), I have no legend at all. If I try to add a legend via addplot, it seems to ignore the positioning that worked in the first instance. What would be a way to combine both a custum legend placement and a text with an angle in one plot?
Code:
sysuse auto, clear
regress headroom trunk
local N_obs1 = e(N)
local beta1 = string(round(_b[trunk],0.001),"%4.3f")
local se1 = string(round(_se[trunk],0.001),"%4.3f")
local constant1 = string(round(_b[_cons],0.001),"%4.3f")
regress headroom length
local N_obs2 = e(N)
local beta2 = string(round(_b[length],0.001),"%4.3f")
local se2 = string(round(_se[length],0.001),"%4.3f")
* original idea of graph
twoway function y = x*500, range(0 40) || function y = 250*x, range(0 40) || ///
(function y = 750*x, range(0 40)), legend(order(1 "Slope 1: `beta1' (SE `se1')" ///
2 "Slope 2: `beta2' (SE `se2')") cols(1) ring(0) size(small) position(11) ///
region(lwidth(none))) legend(size(medsmall))
* trying to add comment with angle
twoway function y = x*500, range(0 40) || function y = 250*x, range(0 40) || ///
(function y = 750*x, range(0 40)), legend(order(1 "Slope 1: `beta1' (SE `se1')" ///
2 "Slope 2: `beta2' (SE `se2')") cols(1) ring(0) size(small) position(11) ///
region(lwidth(none))) legend(size(medsmall))
addplot: scatteri 5000 20 "Some Comment", mlabangle(35)
* second attempt, positioning of legend does not work out
twoway function y = x*500, range(0 40) || function y = 250*x, range(0 40) || ///
function y = 750*x, range(0 40)
addplot: scatteri 5000 20 "Some Comment", mlabangle(35)
addplot: , legend(order(1 "Slope 1: `beta1' (SE `se1')" 2 "Slope 2: `beta2' (SE `se2')") cols(1) ring(0) size(small) position(11) region(lwidth(none))) legend(size(medsmall))

Comment