Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: Controlling alignment of left AND right axes in combined graphs


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: Controlling alignment of left AND right axes in combined graphs
Date   Tue, 20 Mar 2007 17:29:05 -0500

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Marcelo Villafani
> Sent: Monday, March 19, 2007 4:13 PM
> To: [email protected]
> Subject: st: RE: RE: Controlling alignment of left AND right axes in
> combined graphs
> 
> Thank you Scott for your kind help.
> 
> The problem is that the labels in yaxis(2) are left aligned (first digit
> next to yaxis) and I need them right aligned. I tried to solve this
> introducing labstyle() in your code, that is:
> 
> 	ylabel(,angle(h) axis(2) format(%10.0fc) labstyle(right))
> 
> But that makes the problem worst since labstyle() seems only to work with
> text labels.
> 
> Is there a justification option for numeric labels that I am missing?
> 
> Marcelo
> 
> 

I don't think -labstyle()- will help.  If you are only producing a few
graphs, one way would be add spaces to the second yaxis labels to push them
to the right (for example:  -ylabel(0 "     0" 1000(1000)4000, axis(2))- ). 

Scott


clear
set obs 100
gen x = uniform()
gen y1 = uniform()*10
gen y2 = uniform()*4000
gen y3 = uniform()*1000
gen y4 = uniform()*9000 + 4000

//Upper left
qui sum y1
_natscale `=r(min)' `=r(max)' 5
local m1 = r(max)
local l1 = length("`m1'") 
 

//Upper right
qui sum y2
_natscale `=r(min)' `=r(max)' 5
local m2 = r(max)
local l2 = length("`m2'") 
 

//Lower left
qui sum y3
_natscale `=r(min)' `=r(max)' 5
local m3 = r(max)
local l3 = length("`m3'") 
 
//Lower right
qui sum y4
_natscale `=r(min)' `=r(max)' 5
local m4 = r(max)
local l4 = length("`m4'")
 
local diff_left = abs((`l1'- `l3')*2)
local diff_right = abs((`l2' - `l4')*2)+1 

scatter y1 x, ylabel(,angle(h)) xlabel(none) xtitle("") /// 
      ytitle(, margin(0 `diff_left' 0 0)) /// 
      || scatter y2 x, yaxis(2) ylabel(,angle(h) axis(2)) legend(off) /// 
      ytitle(, margin(`diff_right' 0 0 0) axis(2))  /// 
      ylabel(0 "     0" 1000(1000)4000, axis(2)  )  name(gr1, replace)
  
scatter y3 x, ylabel(,angle(h)) xlabel(none)  ytitle(, margin(0 0 0 0)) /// 
      || scatter y4 x, yaxis(2) /// 
      ylabel(4000 "  4000" 6000 "  6000" 8000 "  8000"
10000(2000)14000,angle(h) axis(2)) /// 
      legend(order(1 "Y1 or Y3" 2 "Y2 or Y4"))  /// 
      ytitle(, margin(0  0  0 0) axis(2) ) name(gr2, replace)
 
graph combine gr1 gr2, col(1) name(gr_combine, replace) 
graph drop gr1 gr2



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index