st: Formatting a twoway graph with different scaled y axes

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

st: Formatting a twoway graph with different scaled y axes

René Geppert
Hi, I am using Stata/SE 10 for Windows.

I generated a graph using the following (simplified) code:

. twoway (bar var1 Quarter, yaxis(1) yscale(range(0))) (line var2
Quarter, yaxis(2) )

I do so in order to obtain two y-axes (left and right hand side) with a
different scale. To format the graph properly I experienced two problems:
a) Both axes start at their minimum values, which I can fix for the left
hand side y-axis using yscale(range(0)), which does not work for the
right hand side y-axis for some reason. Why is that and how can I
achieve the same effect there?
b) var 1 and var 2 have 6 observations (at each instance of Quarter).
How can I get a label at each instance in the graph for the line and bar
plot, respectively? That is, show the observation values for example
inside each bar and above the line. The blabel option which one can
usually use in a bar graph does not work in the twoway bar version.

regards, Rene
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: RE: Formatting a twoway graph with different scaled y axes

Nick Cox
Please give a minimal example of a relevant dataset.

Nick
[hidden email]

René Geppert

I am using Stata/SE 10 for Windows.

I generated a graph using the following (simplified) code:

. twoway (bar var1 Quarter, yaxis(1) yscale(range(0))) (line var2
Quarter, yaxis(2) )

I do so in order to obtain two y-axes (left and right hand side) with a
different scale. To format the graph properly I experienced two problems:
a) Both axes start at their minimum values, which I can fix for the left
hand side y-axis using yscale(range(0)), which does not work for the
right hand side y-axis for some reason. Why is that and how can I
achieve the same effect there?
b) var 1 and var 2 have 6 observations (at each instance of Quarter).
How can I get a label at each instance in the graph for the line and bar
plot, respectively? That is, show the observation values for example
inside each bar and above the line. The blabel option which one can
usually use in a bar graph does not work in the twoway bar version.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: Re: Formatting a twoway graph with different scaled y axes

Martin Weiss-5
In reply to this post by René Geppert
Try http://www.stata-journal.com/sjpdf.html?articlenum=gr0019


HTH
Martin
_______________________
----- Original Message -----
From: "René Geppert" <[hidden email]>
To: <[hidden email]>
Sent: Monday, December 08, 2008 8:45 PM
Subject: st: Formatting a twoway graph with different scaled y axes


> Hi, I am using Stata/SE 10 for Windows.
>
> I generated a graph using the following (simplified) code:
>
> . twoway (bar var1 Quarter, yaxis(1) yscale(range(0))) (line var2 Quarter,
> yaxis(2) )
>
> I do so in order to obtain two y-axes (left and right hand side) with a
> different scale. To format the graph properly I experienced two problems:
> a) Both axes start at their minimum values, which I can fix for the left
> hand side y-axis using yscale(range(0)), which does not work for the right
> hand side y-axis for some reason. Why is that and how can I achieve the
> same effect there?
> b) var 1 and var 2 have 6 observations (at each instance of Quarter). How
> can I get a label at each instance in the graph for the line and bar plot,
> respectively? That is, show the observation values for example inside each
> bar and above the line. The blabel option which one can usually use in a
> bar graph does not work in the twoway bar version.
>
> regards, Rene
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: Formatting a twoway graph with different scaled y axes

René Geppert
In reply to this post by Nick Cox
Here you go.

var1   var2    Quarter
.485    28.37    1
.637    25.14    2
1.131  24.62    3
1.364  19.57    4
1.526  3.94      5
1.791  3.56      6


Nick Cox schrieb:

> Please give a minimal example of a relevant dataset.
>
> Nick
> [hidden email]
>
> René Geppert
>
> I am using Stata/SE 10 for Windows.
>
> I generated a graph using the following (simplified) code:
>
> . twoway (bar var1 Quarter, yaxis(1) yscale(range(0))) (line var2
> Quarter, yaxis(2) )
>
> I do so in order to obtain two y-axes (left and right hand side) with a
> different scale. To format the graph properly I experienced two problems:
> a) Both axes start at their minimum values, which I can fix for the left
> hand side y-axis using yscale(range(0)), which does not work for the
> right hand side y-axis for some reason. Why is that and how can I
> achieve the same effect there?
> b) var 1 and var 2 have 6 observations (at each instance of Quarter).
> How can I get a label at each instance in the graph for the line and bar
> plot, respectively? That is, show the observation values for example
> inside each bar and above the line. The blabel option which one can
> usually use in a bar graph does not work in the twoway bar version.
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>  

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: Formatting a twoway graph with different scaled y axes

Scott Merryman
In reply to this post by René Geppert
1.  You need to specify that the range() option is for the second
yaxis:  -yscale(range(0) axis(2)) -

2.  Use -scatter- with the -mlabel()- option.

For example:

sysuse auto,clear
collapse mpg trunk, by(rep)

twoway bar mpg rep, yaxis(1) yscale(range(0) axis(1)) ///
 || line trunk rep , sort yaxis(2) yscale(range(0) axis(2)) ///
 || scatter mpg rep, mlabel(mpg) mlabpos(12) m(none) yaxis(1) ///
 || scatter trunk rep ,mlabel(trunk) mlabpos(3) m(none) yaxis(2) ///
 || ,legend(order(1 3))

Scott


On Mon, Dec 8, 2008 at 1:45 PM, René Geppert
<[hidden email]> wrote:

> Hi, I am using Stata/SE 10 for Windows.
>
> I generated a graph using the following (simplified) code:
>
> . twoway (bar var1 Quarter, yaxis(1) yscale(range(0))) (line var2 Quarter,
> yaxis(2) )
>
> I do so in order to obtain two y-axes (left and right hand side) with a
> different scale. To format the graph properly I experienced two problems:
> a) Both axes start at their minimum values, which I can fix for the left
> hand side y-axis using yscale(range(0)), which does not work for the right
> hand side y-axis for some reason. Why is that and how can I achieve the same
> effect there?
> b) var 1 and var 2 have 6 observations (at each instance of Quarter). How
> can I get a label at each instance in the graph for the line and bar plot,
> respectively? That is, show the observation values for example inside each
> bar and above the line. The blabel option which one can usually use in a bar
> graph does not work in the twoway bar version.
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: Re: Formatting a twoway graph with different scaled y axes

Austin Nichols
In reply to this post by Martin Weiss-5
Note axis() is a suboption of yscale():
 yscale(ra(0) axis(2))
As for the labeling of every point on both graphs (bar and line), I
leave the programming of that chartjunk to others... and predict the
results will be painful to look at.

On Mon, Dec 8, 2008 at 2:57 PM, Martin Weiss <[hidden email]> wrote:

> Try http://www.stata-journal.com/sjpdf.html?articlenum=gr0019
>
>
> HTH
> Martin
> _______________________
> ----- Original Message ----- From: "René Geppert"
> <[hidden email]>
> To: <[hidden email]>
> Sent: Monday, December 08, 2008 8:45 PM
> Subject: st: Formatting a twoway graph with different scaled y axes
>
>
>> Hi, I am using Stata/SE 10 for Windows.
>>
>> I generated a graph using the following (simplified) code:
>>
>> . twoway (bar var1 Quarter, yaxis(1) yscale(range(0))) (line var2 Quarter,
>> yaxis(2) )

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: Formatting a twoway graph with different scaled y axes

Nick Cox
In reply to this post by René Geppert
Other postings have overtaken this.

I read your post as 6 observations for each quarter.

It seems you mean 6 observations, one at each quarter, which would be easier.

The word "each" is treacherous, even to native English speakers, or people in the USA.

Nick
[hidden email]

René Geppert

Here you go.

var1   var2    Quarter
.485    28.37    1
.637    25.14    2
1.131  24.62    3
1.364  19.57    4
1.526  3.94      5
1.791  3.56      6


Nick Cox schrieb:

> Please give a minimal example of a relevant dataset.
>
> Nick
> [hidden email]
>
> René Geppert
>
> I am using Stata/SE 10 for Windows.
>
> I generated a graph using the following (simplified) code:
>
> . twoway (bar var1 Quarter, yaxis(1) yscale(range(0))) (line var2
> Quarter, yaxis(2) )
>
> I do so in order to obtain two y-axes (left and right hand side) with a
> different scale. To format the graph properly I experienced two problems:
> a) Both axes start at their minimum values, which I can fix for the left
> hand side y-axis using yscale(range(0)), which does not work for the
> right hand side y-axis for some reason. Why is that and how can I
> achieve the same effect there?
> b) var 1 and var 2 have 6 observations (at each instance of Quarter).
> How can I get a label at each instance in the graph for the line and bar
> plot, respectively? That is, show the observation values for example
> inside each bar and above the line. The blabel option which one can
> usually use in a bar graph does not work in the twoway bar version.
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/