Statalist The Stata Listserver


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

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


From   "Marcelo Villafani" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Controlling alignment of left AND right axes in combined graphs
Date   Mon, 19 Mar 2007 17:12:58 -0400

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


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Scott Merryman
Sent: Monday, March 19, 2007 12:26 PM
To: [email protected]
Subject: st: RE: Controlling alignment of left AND right axes in combined
graphs


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Marcelo Villafani
> Sent: Sunday, March 18, 2007 9:08 AM
> To: [email protected]
> Subject: st: Controlling alignment of left AND right axes in combined
> graphs
> 
> I am plotting two separate graphs that have horizontal ylabels on the
> right
> and left axes, that later are combined in a col(1) orientation with the
> second plot providing xlabels for both of them. The problem is that the
> y-axes have different numbers of digits and I cannot align the ylabels.
> 
> I found that a similar question was posted last January regarding the left
> axis, but I couldn't adjust the suggested solution to the case where left
> and right y-axes are used simultaneously.
> 

How about this?


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

//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)
display "lengths: `l1' `l2' `l3' `l4' `diff_left' `diff_right' "

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)) name(gr1, replace)
	


scatter y3 x, ylabel(,angle(h)) xlabel(none)  ytitle(, margin(0 0 0 0)) /// 
	|| scatter y4 x, yaxis(2) ylabel(,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


Scott



*
*   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/


*
*   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