Statalist The Stata Listserver


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

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


From   "Marcelo Villafani" <[email protected]>
To   <[email protected]>
Subject   st: Controlling alignment of left AND right axes in combined graphs
Date   Sun, 18 Mar 2007 10:07:33 -0400

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.

Any help would be greatly appreciated.


Marcelo

----------------
ADDENDUM

Adjusting David Elliot�s �ascii art� to my question, graphically my problem
is how to combine:

+---Graph 1---------------------+
|���������� ��������������������|
|�� 5000+-----------------+500 �|
|���� ��|������� ���������|�� ��|
|���� ��|������� ���������|�� ��|
|���� ��|������� ���������|�� ��|
|���� ��|������� ���������|�� ��|
|�� 2500|� Plot 1�������� |250� |
|�� ����|���� ������������|�� ��|
|���� ��|���� ������������|�� ��|
|��� ���|���� ������������|�� ��|
|�� �500|���� ������������|50 ��|
|��� ��0+-----------------+0 ���|
|������������� �Year������ �����|
+-------------------------------+

+---Graph 2------------------------+
|��������������������������� ������|
|�� 100000+-----------------+1000� |
|����� ���|���������������� |� ����|
|�� ������| Plot 2��������� |� ����|
|�� �10000|���������������� |�� ���|
|�� ������|���������������� |�� ���|
|�� ������|���������������� |�� ���|
|�� ��1000|���������������� |100� �|
|���� ���0+-----------------+0 ����|
|������������� �Year������� �������|
+----------------------------------+

To something that looks like this:

+---Combined-----------------------+
|���������� �����������������������|
|� ��5000+------------------+ 500 �|
|���� ���|����������������� |�� ���|
|���� ���|����������������� |�� ���|
|��� ����|����������������� |�� ���|
|�� �����|����������������� |�� ���|
|� ��2500|� Plot 1��������� | 250 �|
|�� �����|��������������� ��|�� ���|
|�� �����|����������������� |�� ���|
|� ������|����������������� |�� ���|
| ����500|����������������� | �50 �|
| ������0+------------------+ ��0 �|
|������������������������ ���������|
|� 100000+------------------+1000 �|
|�� �����| �����������������|� ����|
|� �10000| Plot 2 ����������|�� ���|
|�� �����|��������� ��������|�� ���|
|�� �1000|���������� �������| 100 �|
|���� ��0+------------------+� �0 �|
|��������������� Year� ������������|
+----------------------------------+

On the other hand, Scott Merryman (2/5/2007) provided this neat solution to
David�s left axis alignment problem:

clear
set obs 100
gen x = uniform()
gen y1 = uniform()*10
gen y2 = uniform()*100
gen y3 = uniform()*400
gen y4 = uniform()*90000

foreach i of numlist 1 3 {
qui sum y`i'
_natscale `=r(min)' `=r(max)' 5
local m`i' = r(max)
local l`i' = length("`m`i''") 

local j = `i' + 1
qui sum y`j'
_natscale `=r(min)' `=r(max)' 5
local m`j' = r(max)
local l`j' = length("`m`j''")
local diff = (`l`j''- `l`i'')*2 

display "lengths: " "`l`i'' `l`j'' `diff'"

scatter y`i' x, ylabel(,angle(h)) xlabel(none) xtitle("") ///� ytitle(,
margin(0 `diff'� 0 0 )) name(gr1, replace) scatter y`j' x, ylabel(,angle(h))
name(gr2,replace) ///� ytitle(, margin(0 0 0 0 )) graph combine gr1 gr2,
col(1) name(gr_`j', replace) graph drop gr1 gr2 }

Thanks for your help once again.


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